开发者

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

开发者 https://www.devze.com 2023-01-27 16:45 出处:网络
I have stored procedure in MySQL, something lik开发者_Python百科e the below: create procedure SP_Test (input1 varchar(20))

I have stored procedure in MySQL, something lik开发者_Python百科e the below:

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?


Use ROW_COUNT():

SELECT ROW_COUNT();


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

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


Try the following code:

int mysql_affected_rows ([ resource $link_identifier = NULL ] )
0

精彩评论

暂无评论...
验证码 换一张
取 消