请使用PLSQL删除bigt中的owner='SYS'的数据,每次删除500条,删除掉50000条即可。

来源:互联网 发布:哪里可以购买淘宝账号 编辑:程序博客网 时间:2024/06/10 21:17
构造测试表请使用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';46876declare    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秒,不知道什么原因导致这么慢,按理说是应该很快出来的。

原创粉丝点击