請使用PLSQL刪除bigt中的owner='SYS'的數據,每次刪除500條,刪除掉50000條即可。

構造測試表
請使用PLSQL刪除bigt中的owner='SYS'的數據,每次刪除500條,刪除掉50000條即可。
技術要求:
1、遊標
2、循環結構
3、批量forall處理
---在命令窗口執行
exec create_table('t1');--默認創建10萬的數據量
---SQL窗口 begin  create_table('t1'); end ;
select count(*) from t1 where owner='SYS';46876
declare
    cursor t1_tab_cur is
        select object_id from t1 where owner = 'SYS';
    type t1_tab_type is table of t1.object_id%type;
    t1_tab t1_tab_type;
begin
    open t1_tab_cur;
    loop
        fetch t1_tab_cur bulk collect
            into t1_tab limit 5000;
        forall i in 1 .. t1_tab.count
            delete from t1 where object_id = t1_tab(i);
        commit;
        exit when t1_tab.count < 5000;
    end loop;
    close t1_tab_cur;
end;
---------但是花了329秒,不知道什麼原因導致這麼慢,按理說是應該很快出來的。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章