使用存储过程在mysql中更新表

时间:2022-07-17 11:01:35

I have stored procedure in mysql. The procedure is created, but when the procedure is called I get an error:

我在mysql中存储过程。该过程已创建,但调用该过程时出现错误:

"Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Editor -> Query Editor and reconnect."

“错误代码:1175。您正在使用安全更新模式,并且您尝试更新没有使用KEY列的WHERE的表要禁用安全模式,请在首选项 - > SQL编辑器 - >查询编辑器中切换选项并重新连接。”

Here is the procedure:

这是程序:

------------------------------------------------
drop procedure if exists update_per_det;

delimiter //

create procedure update_per_det(IN name varchar(30))

begin

 DECLARE age1 int;

set age1=(select CalAge(name));

update  per_det set age=age1 where username=name;

end;//

delimiter ;

How can I solve this issue?

我该如何解决这个问题?

1 个解决方案

#1


2  

Try this:

set age1=(select CalAge(name));

SET SQL_SAFE_UPDATES=0;

update  per_det set age=age1 where username=name;

#1


2  

Try this:

set age1=(select CalAge(name));

SET SQL_SAFE_UPDATES=0;

update  per_det set age=age1 where username=name;