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;