根据value分数设置grade等级
BEGIN
declare isloop int DEFAULT 1; -- 定义isloop 设置初始值为-1
declare tvalue int;
declare tid int;
declare tgrade VARCHAR(50);
declare cur cursor for select id,value from score; -- 定义游标
declare continue HANDLER for not found set isloop=1; -- 设置游标结束
OPEN cur; -- 开启游标
while isloop>0
DO -- do while循环代码 end while
fetch cur into tid,tvalue;
if tvalue>=90 -- if 条件 then 代码 elseif 条件 then 代码 else 代码 end if
then set tgrade='优秀';
elseif tvalue>=80
then set tgrade='良好';
elseif tvalue>=70
then set tgrade='一般';
elseif tvalue>=60
then set tgrade='及格';
ELSE
set tgrade='不及格';
end if;
update score set grade=tgrade where id=tid; -- 设置等级
end while;
close cur; -- 关闭游标
END