【发布时间】:2014-01-09 02:29:06
【问题描述】:
我创建了两个表学生和年级。学生表包含 id(PK),name,mark,address 列。我在其中插入了 10 个值。在等级表中有两个列 stud_id(外键)和 stud_status。在年级我必须在存储过程中编写一个游标,从学生表插入到成绩表中。如果学生分数在成绩表中高于 50,则该条件将在 stud_status 和 stud_id 中存储为“G”。如果标记 = 50,则应存储“E”,否则为“L” 我使用下面的代码。我正在使用 MySQL Workbench 6.0。
use test;
delimiter $$
drop procedure if exists `p_status` $$
create procedure `p_status`()
begin
declare s_stud_mark int(111);
declare s_stud_id int(111);
declare cur_stud cursor For Select stud_id,stud_mark from student where stud_id is not null;
open cur_stud;
fetch cur_stud into s_stud_mark,s_stud_id;
if(stud_mark > 50) then
set s_stud_mark='G';
insert into grade(`stud_id`,`stud_staus`)values(s_stud_id,s_stud_mark);
else if(stud_mark = 50) then
set s_stud_mark='E';
insert into grade(`stud_id`,`stud_status`) values(s_stud_id,s_stud_mark);
else
set s_stud_mark='L';
insert into grade(`stud_id`,`stud_status`)values(s_stud_id,s_stud_mark);
end if ;
end if ;
close cur_stud;
end $$
delimiter ;
但它显示错误为“错误代码:1054。'字段列表'中的未知列'stud_mark'”
有人回复
【问题讨论】:
标签: mysql stored-procedures cursor mysqldump mysql-workbench