Skip to main content
Version: V1.0.0

ROW_COUNT

Declaration

ROW_COUNT()

Description

Returns the number of rows affected by the executed SQL statement.

ROW_COUNT returns different values based on the type of statement:

  • DDL statements: returns 0.

  • DML statements other than SELECT: returns the number of rows affected.

    Specifically, UPDATE statements return the actual number of rows affected.

  • SELECT statements: returns -1 if the execution result is a set, or the number of rows affected if the SELECT statement changes the state of rows.

    For example, SELECT .... INTO statements return the number of rows inserted.

Examples

INSERT INTO t VALUES(1),(2),(3);
Query OK, 3 rows affected (0.02 sec)
Records: 3 Duplicates: 0 Warnings: 0

SELECT ROW_COUNT();
+-------------+
| ROW_COUNT() |
+-------------+
| 3 |
+-------------+
1 row in set (0.001 sec)