一次取得所有待刪除資料的ROWID,然後分批小量刪除資料
Set Serveroutput On;
DECLARE
V_DATE DATE;
Type V_Rowid Is Table Of Varchar2(100) Index By Binary_Integer;
Var_Rowid V_Rowid;
Cursor V_Cur Is Select /*+parallel(a,2)*/Rowid From Hr.Employee Where LoginDate <= V_Date;
Begin
V_Date := To_Date(To_Char(Trunc(Sysdate-60),'YYYY-MM-DD HH24:MI:SS'),'YYYY-MM-DD HH24:MI:SS');
Open V_Cur ;
Loop
Fetch V_Cur Bulk Collect
Into Var_Rowid Limit 10000;
Forall I In 1 .. Var_Rowid.Count
Delete From Hr.Employee Where Rowid =Var_Rowid(I);
Commit;
Exit When V_Cur%Notfound Or V_Cur%Notfound Is Null;
End Loop;
Close V_Cur;
End;
0 意見:
張貼留言