简体   繁体   English

存储过程中的神秘运行时错误

[英]mysterious runtime error in stored proc

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//

the proc-creation query gets executed. proc-creation查询被执行。 But when I call stugrade() gives me an error 1241 (21000). 但是,当我调用stugrade()时,出现错误1241(21000)。

It looks to me like this line is causing your problem. 在我看来,这行引起您的问题。

set total=(v_sub1,v_sub2,v_sub3);

MySQL can only handle scalars in this sort of context. MySQL只能在这种情况下处理标量。 You may want 你可能想要

set total = v_sub1+v_sub2+v_sub3;

Also, CONCAT() will take multiple parameters. 同样, CONCAT()将采用多个参数。 That is, while this is correct: 也就是说,这是正确的:

select concat(concat(concat('marks-->',v_sub1),v_sub2),v_sub3) as "subject wise marks";

It can be recast as 可以重铸为

select concat('marks-->',v_sub1,v_sub2,v_sub3) as "subject wise marks";

if it's easier. 如果更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM