解题思路:先定义一个变量cou,使用游标读取数据,每读取一行数据,就把值赋给cou,以cou.cscore 与60 进行比较,大于则-5分,小于则+20分。
1、course_1 表
select * from course_1;
2、详细实现代码
declare
cou course_1%rowtype;
cursor youbiao is select * from course_1;
begin
open youbiao;
loop
fetch youbiao into cou;
exit when youbiao%notfound;
if cou.cscore < 60 then
update course_1 set cscore = cscore +20
where cou.cno = course_1.cno and cou.cname = course_1.cname
;
elsif cou.cscore >60 then
update course_1 set cscore = cscore - 5
where cou.cno = course_1.cno and cou.cname = course_1.cname;
end if;
dbms_output.put_line('修改成功');
end loop;
close youbiao;
commit;
end;
3、结果
可以看到,成功实现。