declare
   empr emp%rowtype;
   cursor curemp is select * from emp for update of sal;
begin
   open curemp;
   loop 
      fetch curemp into empr;
      fetch curemp into empr;
      dbms_output.put_line(empr.ename); 
       update emp set sal =6000 WHERE CURRENT OF curemp;
      exit when curemp%notfound;     
   end loop;
end ;
结果:
ORA-01410: 无效的 ROWID
ORA-06512: 在line 12

解决方案 »

  1.   

    你的exit when cyremp%notfound 应该写在
    fetch curemp into empr; 
    的下一行,而不是最后.
      

  2.   

    你取2,4,6,8.....的记录?
    改成这样看看.
    declare
      empr emp%rowtype;
      cursor curemp is
        select * from emp for update of sal;
    begin
      open curemp;
      loop
        fetch curemp
          into empr;
        exit when curemp%notfound;
        fetch curemp
          into empr;
        exit when curemp%notfound;
        dbms_output.put_line(empr.ename);
        update emp set sal = 6000 WHERE CURRENT OF curemp;
        commit;
      end loop;
    end;
      

  3.   

    谢谢你,我明白为什么了,所以也不有能While 语句循环读取