oracle数据库使用

来源:百度知道 编辑:UC知道 时间:2024/06/08 00:08:50
编写PL/SQL块,使用游标更新scott.emp所有员工的工资,要求如下
如果剖门编号为10,增加工资10%;
如果部门编号为20,增加工资5%,补助(comm列)200元
如果部门编号为30,仅当工资低于2500的员工工资增加300元

declare ls_id varchar2(20);
cursor cur is select distinct id from emp;
begin
open cur;
loop
fetch cur into ls_id;
exit when cur%notfound;
if ls_id='10' then
update emp set gongzi=gongzi*1.1 where id=ls_id;
End If;
If ls_id='20' Then
Update emp Set gongzi=gongzi*1.05,comm=200 Where Id=ls_id;
End If;
If ls_id='30' Then
Update emp Set gongzi=gongzi+300 Where Id=ls_id And gongzi<2500;
End If;
end loop;
close cur;
end;

1楼的有2处错误

1.定义游标的时候错了,应该是
cursor cur is select id from emp for update;

2.进行修改操作的时候错了,应该是
if ls_id=10 then
update emp set gongzi=gongzi*1.1 where current of cur;
同理下面的2个if后的update语句都要修改