ROW_COUNT()
This page is part of MariaDB's Documentation.
The parent of this page is: Functions for MariaDB Xpand
Topics on this page:
Overview
Returns the number of rows updated, inserted, or deleted by the preceding statement.
USAGE
ROW_COUNT()
DETAILS
ROW_COUNT() is an information function that returns the number of rows affected by the preceding statement.
The return value is 0 for a DDL statement, such as CREATE TABLE.
The return value is -1 for a SELECT unless that statements outputs data into a file, in which case it returns the number of rows written.
The return value for an INSERT, UPDATE, or DELETE is the count of rows inserted, updated, or deleted.
The returns value of a REPLACE statement is 2 if it updated a value in an existing row or 1 if it either inserted a new row or made no changes.
EXAMPLES
CREATE TABLE row_count_example (
a INT PRIMARY KEY,
b INT
);
SELECT ROW_COUNT();
+-------------+
| ROW_COUNT() |
+-------------+
| 0 |
+-------------+
INSERT INTO row_count_example VALUES
(1,1), (2,2), (3,3);
SELECT ROW_COUNT();
+-------------+
| ROW_COUNT() |
+-------------+
| 3 |
+-------------+
UPDATE row_count_example SET b = 2
WHERE a = 1;
SELECT ROW_COUNT();
+-------------+
| ROW_COUNT() |
+-------------+
| 1 |
+-------------+
UPDATE row_count_example
SET b = 2
WHERE a = 2;
SELECT ROW_COUNT();
+-------------+
| ROW_COUNT() |
+-------------+
| 1 |
+-------------+
DELETE FROM row_count_example
WHERE a < 3;
SELECT ROW_COUNT();
+-------------+
| ROW_COUNT() |
+-------------+
| 2 |
+-------------+
-- Row is already 3, 3
REPLACE INTO row_count_example VALUES (3, 3);
SELECT ROW_COUNT();
+-------------+
| ROW_COUNT() |
+-------------+
| 2 |
+-------------+
REPLACE INTO row_count_example VALUES (3, 1);
SELECT ROW_COUNT();
+-------------+
| ROW_COUNT() |
+-------------+
| 2 |
+-------------+
REPLACE INTO row_count_example VALUES (4, 4);
SELECT ROW_COUNT();
+-------------+
| ROW_COUNT() |
+-------------+
| 1 |
+-------------+
