如何获取受 MySQL 查询影响的总行数?
mysqlmysqli database
MySQL ROW_COUNT() 可用于获取受 MySQL 查询影响的总行数。为了说明这一点,我们正在创建一个过程,借助该过程我们可以在表中插入记录,它将向我们显示有多少行受到了影响。
示例
mysql> Delimiter // mysql> CREATE PROCEDURE `query`.`row_cnt` (IN command VarChar(60000)) -> BEGIN -> SET @query = command; -> PREPARE stmt FROM @query; -> EXECUTE stmt; -> SELECT ROW_COUNT() AS 'Affected rows'; -> END // Query OK, 0 rows affected (0.00 sec) mysql> Delimiter ; mysql> Create table Testing123(First Varchar(20), Second Varchar(20)); Query OK, 0 rows affected (0.48 sec) mysql> CALL row_cnt("INSERT INTO testing123(First,Second) Values('Testing First','Testing Second');"); +---------------+ | Affected rows | +---------------+ | 1 | +---------------+ 1 row in set (0.10 sec) Query OK, 0 rows affected (0.11 sec)
以上结果集显示将数据插入‘testing123’表后,I行受到影响。