create or replace procedure p
is
cursor c is
select * from emp2 for update;
begin
for v_emp in c loop
if (v_emp.deptno = 10) then
update emp2 set sal = sal + 10 where current of c;
elsif (v_emp.deptno = 20) then
update emp2 set sal = sal + 20 where current of c;
else
update emp2 set sal = sal + 50 where current of c;
end if;
end loop;
commit;
end;
/
------解决方案--------------------
编译通过,我用的是Scott方案下的emp表,你可以改回你的emp2表.
- SQL code
CREATE OR REPLACE PROCEDURE pIS CURSOR c IS SELECT * FROM emp FOR UPDATE;BEGIN FOR v_emp IN c LOOP IF v_emp.deptno = 10 THEN UPDATE emp SET sal = sal + 10 WHERE CURRENT OF c; ELSIF (v_emp.deptno = 20) THEN UPDATE emp SET sal = sal + 20 WHERE CURRENT OF c; ELSE UPDATE emp SET sal = sal + 50 WHERE CURRENT OF c; END IF; END LOOP; COMMIT;END;