获取 MySQL 更新语句中受影响的行数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4306084/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 17:51:18 来源:igfitidea点击:
Get the number of affected rows in a MySQL update statement?
提问by Alaa
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?
如何确定此更新更改了多少行?
回答by Joe Stefanelli
回答by Randy
one way, not very optimal is to simply do a select before you do the update.
一种不太理想的方法是在更新之前简单地进行选择。
select count(*) from table1 where country = 'country1'
回答by Harvey
Try the following code:
试试下面的代码:
int mysql_affected_rows ([ resource $link_identifier = NULL ] )