DELIMITER //
drop procedure if exists stugrade//
create procedure stugrade()
begin
declare v_pid,v_sub1,v_sub2,v_sub3 int;
declare total int default 0;
declare v_finished int default 0;
declare per decimal(10,2);
declare stud_cur cursor for select sid,sub1,sub2,sub3 from student;
declare continue handler for not found set v_finished=1;
set per=0;
open stud_cur;
label1:loop
fetch stud_cur into v_pid,v_sub1,v_sub2,v_sub3;
if v_finished=1 then
leave label1;
end if;
set total=(v_sub1,v_sub2,v_sub3);
set per=total/3;
select concat(concat(concat('marks-->',v_sub1),v_sub2),v_sub3) as "subject wise marks";
select concat('total marks of student',total) as "total marks";
select concat('Percentage of student',per) as "percentage";
if(per>=66) then
select concat('','Distinction') as "class";
elseif(per<66 and per>=60) then
select concat('','first') as "class";
elseif(per<60 and per>=55) then
select concat('','higher Second') as "class";
elseif(per<55 and per>=50) then
select concat('','second') as "class";
elseif(per<50 and per>=40) then
select concat('','pass') as "class";
else
select concat('','fail') as "class";
end if;
end loop label1;
close stud_cur;
end//
proc-creation 查询被执行。但是当我调用 stugrade() 时,会出现错误 1241 (21000)。