CREATE PROCEDURE updateStudent(IN intime varchar(20))
BEGINDECLARE stuid int;
DECLARE syear int;
DECLARE b int default 0; #终止循环
declare cur cursor for select tid,student_year from table_test where input_time<intime;
#这把游标异常后捕捉并设置循环使用 变量b为1跳出循环。
declare continue handler for not found set b = 1;
/*开游标*/
OPEN cur;
/*游标向下走一步,将查询出来的值付给定义的变量*/
FETCH cur INTO stuid,syear;
#有多少处理多少,直到没有数据为止
while b<>1 do
case syear
when 11 then
update table_test set student_year=1 where tid=stuid;
when 1 then
update table_test set student_year=2 where tid=stuid;
when 2 then
update table_test set student_year=3 where tid=stuid;
when 3 then
update table_test set student_year=4 where tid=stuid;
when 4 then
update table_test set student_year=5 where tid=stuid;
when 5 then
update table_test set student_year=6 where tid=stuid;
when 6 then
update table_test set student_year=7 where tid=stuid;
when 7 then
update table_test set student_year=8 where tid=stuid;
when 8 then
update table_test set student_year=9 where tid=stuid;
when 9 then
update table_test set student_year=10 where tid=stuid;
when 10 then
update table_test set student_year=10 where tid=stuid;
ELSE
update table_test set student_year=1 where tid=stuid;
end case;
FETCH cur INTO stuid,syear;
end while;
close cur;
end;