WHERE CURRENT OF WHERE CURRENT OF YOUR_CURSOR_NAME 其实还是很有用的,特别是在循环游标中。
例如:需要把所有job=SALESMAN的加5%的工资。
=CLERK的加10%的工资。
=MANAGER加15%的工资。
CODE:
declare
cursor myc is
select * from emp for update;
begin
for v_row in myc loop
if v_row.job='SALESMAN' then
update emp set sal=sal*1.05 where current of myc;
elsif v_row.job='CLERK' then
update emp set sal=sal*1.10 where current of myc;
elsif v_row.job='MANAGER' then
update emp set sal=sal*1.15 where current of myc;
end if;
end loop;
commit;
exception
when others then
rollback;
raise;
end;
cursor myc is
select * from emp for update;
begin
for v_row in myc loop
if v_row.job='SALESMAN' then
update emp set sal=sal*1.05 where current of myc;
elsif v_row.job='CLERK' then
update emp set sal=sal*1.10 where current of myc;
elsif v_row.job='MANAGER' then
update emp set sal=sal*1.15 where current of myc;
end if;
end loop;
commit;
exception
when others then
rollback;
raise;
end;
本文介绍了一个利用PL/SQL中的WHERE CURRENT OF子句来更新循环游标的示例。通过遍历包含不同职位的数据,并根据职位类型更新员工薪资,展示了如何有效地使用这一特性。示例包括为SALESMAN、CLERK和MANAGER等不同职位增加不同比例的薪资。
636

被折叠的 条评论
为什么被折叠?



