简体   繁体   English

获取 MySQL 更新语句中受影响的行数?

[英]Get the number of affected rows in a MySQL update statement?

I have stored procedure in MySQL, something like the below:我在 MySQL 中有存储过程,如下所示:

create procedure SP_Test (input1 varchar(20))
begin
update Table1 set Val1='Val' where country=input1;
//I want to see if this update changed how many rows and 
//do some specific action based on this number
....
end

How can I determine how many rows were changed by this update?如何确定此更新更改了多少行?

使用ROW_COUNT()

SELECT ROW_COUNT();

一种不太理想的方法是在更新之前简单地进行选择。

select count(*) from table1 where country = 'country1'

试试下面的代码:

int mysql_affected_rows ([ resource $link_identifier = NULL ] )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM