sql*plus 游标问题

来源:百度知道 编辑:UC知道 时间:2024/09/20 11:47:53
把成绩大于60分的学分加到学生已获学分一项中
create or replace procedure sum_cont is
cursor got is
select s#
from s;
s1 got%rowtype;
got_credit char(6);
begin
open got;
loop
fetch got into s1;
exit when got%notfound;
select credit into got_credit
from c,report_card
where c.c#=report_card.c# and score>=60;
update s
set have_credit=have_credit+got_credit
where s#=s1.s#;
end loop;
close got;
commit;
end;
/

有问题么?怎么改正?
几位给的答案都不行啊,还有没有建议了?
答案只要对了,我会追加分数的!

你不要在表的查询游标中更新这个表的数据,如果你要这样做,可以在定义游标时加上:for update,即:
cursor got is
select s#
from s
for update;
在程序循环中用where current of cursor去更新:
create or replace procedure sum_cont is
cursor got is
select s#
from s for update;
s1 got%rowtype;
got_credit char(6);
begin
open got;
loop
fetch got into s1;
exit when got%notfound;
select credit into got_credit
from c,report_card
where c.c#=report_card.c# and score>=60;
update s
set have_credit=have_credit+got_credit
where current of got;
end loop;
close got;
commit;
end;
/

select credit into got_credit
from c,report_card
where c.c#=report_card.c# and score>=60;
出来的结果是一个么?
另外你的代码没有注释,没有错误提示,看着好累啊!
表的字段也不知道什么意思

select credit into got_credit
from c,report_card
where c.c#=report_card.c# and score>=60;

这个地方的问题?oracle中select into代表