如何获取受 MySQL 查询影响的总行数?
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”表后,影响了一行。
广告