遊標在fetch過程中不允許更新自己
阿新 • • 發佈:2019-02-03
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
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