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创建查询。但是当我打电话给stugrade()给我一个错误1241(21000)。
答案 0 :(得分:0)
我觉得这条线路正在引起你的问题。
var clientVariable = true;
MySQL只能处理这种上下文中的标量。你可能想要
set total=(v_sub1,v_sub2,v_sub3);
此外,set total = v_sub1+v_sub2+v_sub3;
将采用多个参数。也就是说,虽然这是正确的:
CONCAT()
可以重铸为
select concat(concat(concat('marks-->',v_sub1),v_sub2),v_sub3) as "subject wise marks";
如果它更容易。