mysql 存储过程:提供查询语句并返回查询执行影响的行数
DELIMITER $$ DROP PROCEDURE IF EXISTS `p_get_select_row_number`$$ CREATE PROCEDURE `test_cases`.`p_get_select_row_number`(IN p_select_sql VARCHAR(500), OUT p_count INT(8) ) BEGIN -- 声明 DECLARE cnt INT DEFAULT 0; DECLARE stmt VARCHAR(200); -- 赋值 SET @stmt = CONCAT(p_select_sql); -- prepare PREPARE s1 FROM @stmt; -- 执行 EXECUTE s1; -- 获取查询影响的行数 SET @cnt = FOUND_ROWS(); -- 输出影响函数 SELECT @cnt INTO p_count ; END$$ DELIMITER ; CALL p_get_select_row_number('select * from report', @qqq); SELECT @qqq;
执行结果
8 rows in set (0.00 sec)
Query OK, 1 row affected (0.05 sec)
mysql> SELECT @qqq;
+------+
| @qqq |
+------+
| 8 |
+------+
1 row in set (0.00 sec)