1. 程式人生 > >遊標在fetch過程中不允許更新自己

遊標在fetch過程中不允許更新自己

SQL> Declare
  2    vname dept.dname%Type;
  3  Begin
  4    For csr In(Select * From dept For Update) Loop
  5        Update dept Set dname=Upper(dname) Where deptno=csr.deptno Returning dname Into vname;
  6        dbms_output.put_line(vname);
  7        Commit;
  8    End Loop;
  9  End;
 10  /
ACCOUNTING
Declare
  vname dept.dname%Type;
Begin
  For csr In(Select * From dept For Update) Loop
      Update dept Set dname=Upper(dname) Where deptno=csr.deptno Returning dname Into vname;
      dbms_output.put_line(vname);
      Commit;

  End Loop;
End;
ORA-01002: 提取違反順序
ORA-06512: 在 line 4


SQL> 
SQL> Declare
  2    vname dept.dname%Type;
  3  Begin
  4    For csr In(Select * From dept For Update) Loop
  5        Update dept Set dname=Upper(dname) Where deptno=csr.deptno Returning dname Into vname;
  6        dbms_output.put_line(vname);
  7    End Loop;
  8    Commit;

  9  End;
 10  /
ACCOUNTING
RESEARCH
SALES
OPERATIONS
PL/SQL procedure successfully completed