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)。
最佳答案
在我看来,这行引起您的问题。
set total=(v_sub1,v_sub2,v_sub3);
MySQL只能在这种情况下处理标量。你可能想要
set total = v_sub1+v_sub2+v_sub3;
此外,
CONCAT()
将采用多个参数。也就是说,这是正确的:select concat(concat(concat('marks-->',v_sub1),v_sub2),v_sub3) as "subject wise marks";
可以重铸为
select concat('marks-->',v_sub1,v_sub2,v_sub3) as "subject wise marks";
如果更容易。