创建一个 MySQL 存储过程,用于计算受 MySQL 查询影响的行数?


以下是计算受 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)

更新日期:22-06-2020

1 千次 + 查看

开启你的职业生涯

完成本课程,获得认证

开始
广告