有個需求,要求清理8TB的數(shù)據(jù),只保留一個月的數(shù)據(jù),現(xiàn)有數(shù)據(jù)量由2010年至2018年底都需要清除,因此寫了通用的該清除腳本。該表為沒有分區(qū)的含有BLOB的大表,一共由三列,file_no,BLOB,還有create_time列,其中file_no為主鍵,create_time非空。
創(chuàng)新互聯(lián)不只是一家網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司;我們對營銷、技術(shù)、服務(wù)都有自己獨特見解,公司采取“創(chuàng)意+綜合+營銷”一體化的方式為您提供更專業(yè)的服務(wù)!我們經(jīng)歷的每一步也許不一定是最完美的,但每一步都有值得深思的意義。我們珍視每一份信任,關(guān)注我們的網(wǎng)站制作、網(wǎng)站設(shè)計質(zhì)量和服務(wù)品質(zhì),在得到用戶滿意的同時,也能得到同行業(yè)的專業(yè)認(rèn)可,能夠為行業(yè)創(chuàng)新發(fā)展助力。未來將繼續(xù)專注于技術(shù)創(chuàng)新,服務(wù)升級,滿足企業(yè)一站式營銷型網(wǎng)站需求,讓再小的品牌網(wǎng)站設(shè)計也能產(chǎn)生價值!
腳本如下:
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_thread_count in varchar2, -- thread number of the sql which use parallel hint
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('Number of threads is ' || to_char(PI_thread_count) || ';');
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 hh34: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 hh34:mi:ss'));
end loop;
commit;
dbms_output.put_line('End to batch delete. Timestamp is ' || to_char(sysdate, 'yyyy-mm-dd hh34:mi:ss'));
end proc_batch_delete;
1.該圖
2.執(zhí)行語句
3.輸入值
4.顯示值
pi_table_name 需要刪除數(shù)據(jù)的表名
pi_where_condition 選擇條件
pi_thread_count并發(fā)線程數(shù)
pi_commit_count 每次刪除和提交事務(wù)數(shù)量
文章名稱:批量清除一個表的數(shù)據(jù),TB級別數(shù)據(jù)。
網(wǎng)站路徑:http://aaarwkj.com/article8/gghhop.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、App設(shè)計、靜態(tài)網(wǎng)站、建站公司、微信小程序、網(wǎng)頁設(shè)計公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)