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

时间:2022-05-21 22:56:55

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?

如何确定此更新更改了多少行?

3 个解决方案

#1


16  

Use ROW_COUNT():

使用ROW_COUNT():

SELECT ROW_COUNT();

#2


0  

one way, not very optimal is to simply do a select before you do the update.

一种方法,不是非常优化,只需在进行更新之前进行选择。

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

#3


-1  

Try the following code:

请尝试以下代码:

int mysql_affected_rows ([ resource $link_identifier = NULL ] )

#1


16  

Use ROW_COUNT():

使用ROW_COUNT():

SELECT ROW_COUNT();

#2


0  

one way, not very optimal is to simply do a select before you do the update.

一种方法,不是非常优化,只需在进行更新之前进行选择。

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

#3


-1  

Try the following code:

请尝试以下代码:

int mysql_affected_rows ([ resource $link_identifier = NULL ] )