mysql触发

create procedure agex(in addage1 int,in addage2 int)
begin
declare curl_stu_id int;
declare curl_stu_sex varchar(5);
declare done int default 0;
declare curl_student cursor for select stu_id,stu_sex from t_student;
declare continue handler for not found set done=1; //若没有数据返回则将变量done设置为1
open curl_student;
repeat
fetch curl_student into curl_stu_id,curl_stu_sex;
if not done then
if curl_stu_Sex='男' then
update t_student set age=age+addage1 where stu_id=curl_stu_id;
else
update t_student set age=age+addage2 where stu_id=curl_stu_id;
end if;
end if;
until done end repeat;
close curl_student;
end

原文地址:https://www.cnblogs.com/mengluo/p/5381749.html