批量清除一個表的數據,TB級別數據。
腳本如下:
create or replace procedure proc_batch_delete(PI_table_name in varchar2, -- table name which will delete data
PI_where_condition in varchar2, -- delete sql condition
PI_commit_count in varchar2) is -- per delete count and commit count
v_delete integer;
v_sql varchar2(2000);
begin
dbms_output.put_line(‘Delete table is ‘ || PI_table_name || ‘;‘);
dbms_output.put_line(‘Where condition is ‘ || PI_where_condition || ‘;‘);
dbms_output.put_line(‘Commit count is ‘ || to_char(PI_commit_count) || ‘;‘);
dbms_output.put_line(‘Now start to batch delete. Timestamp is ‘ || to_char(sysdate, ‘yyyy-mm-dd hh24:mi:ss‘));
v_delete := 0;
execute immediate ‘alter session enable parallel dml‘;
v_sql := ‘delete /+ parallel(‘||PI_table_name || ‘ ‘ || PI_thread_count ||‘) / from ‘
|| PI_table_name ||‘ where ‘|| PI_where_condition || ‘and rownum <= ‘ || PI_commit_count;
dbms_output.put_line(‘Sql is ‘ || v_sql);
while 1=1 loop
EXECUTE IMMEDIATE v_sql;
if SQL%NOTFOUND then
exit;
else
v_delete:=v_delete + SQL%ROWCOUNT;
end if;
commit;
dbms_output.put_line(‘already deleted :‘ || to_char(v_delete) ||‘.Timestamp is‘ || to_char(sysdate, ‘yyyy-mm-dd hh24:mi:ss‘));
end loop;
commit;
dbms_output.put_line(‘End to batch delete. Timestamp is ‘ || to_char(sysdate, ‘yyyy-mm-dd hh24:mi:ss‘));
end proc_batch_delete;
1.該圖
2.執行語句
3.輸入值
4.顯示值
pi_table_name 需要刪除數據的表名
pi_where_condition 選擇條件
pi_thread_count並發線程數
pi_commit_count 每次刪除和提交事務數量
批量清除一個表的數據,TB級別數據。