Warning
SingleStore 9.0 gives you the opportunity to preview, evaluate, and provide feedback on new and upcoming features prior to their general availability. In the interim, SingleStore 8.9 is recommended for production workloads, which can later be upgraded to SingleStore 9.0.
ROW_ COUNT
On this page
Returns the number of rows inserted, updated, or deleted by the preceding statement.
Syntax
ROW_COUNT()
Arguments
-
None.
Return Type
int
Examples
The following shows how to use ROW_
in a query after running an INSERT
:
DROP TABLE IF EXISTS account;CREATE TABLE account(id int, amount decimal(10,2));INSERT account VALUES(1, 10.00), (2, 30.00);
SELECT ROW_COUNT();
+-------------+
| ROW_COUNT() |
+-------------+
| 2 |
+-------------+
This example shows how an application can raise an error if a ROW_
result is different than expected after a DELETE
:
DELIMITER //CREATE OR REPLACE PROCEDURE delete_account(_id int) RETURNS int ASDECLARE _row_count int = -1;BEGINDELETE FROM account WHERE account.id = _id;_row_count = row_count();IF _row_count = 0 THENRAISE user_exception(CONCAT("No rows deleted for account ", _id));END IF;RETURN _row_count;END //DELIMITER ;
Example use:
ECHO delete_account(3);ERROR 2242 (HY000): Unhandled exceptionType: ER_USER_RAISEMessage: No rows deleted for account 3Callstack:#0 Line 7 in `db1`.`delete_account`ECHO delete_account(1);+--------+| RESULT |+--------+| 1 |+--------+
Last modified: February 24, 2023