需求:
專案中有一張表大概有7000多萬條資料,造成表空間已滿,需要清理部分資料,打算清理3000萬。
2b 做法:
delete from table_name where id > '40000000';
備註:select count(1) from table_name where id > 'his_batch_4000000'; 的結果大概有3000萬條資料。
影響:
刪了n個小時也沒執行完,最終強制停止,造成表被鎖。(沒有管理員許可權,需要聯絡dba 才能解鎖)
改進:
declare
ncount number;
nrownumber number;
begin
nrownumber := 0;
loop
ncount := 0;
select count(1)
into ncount
from table_name
where id > 'his_batch_4000000'
and rownum < 10000;
if ncount > 0 then
delete from table_name
where id > 'his_batch_4000000'
and rownum < 10000;
commit;
nrownumber := nrownumber + ncount;
dbms_output.put_line(nrownumber);
else
exit;
end if;
end loop;
end;
hive刪除表中部分資料
insert overwrite table table name select from table name where 可以看出,刪除的本質就是覆蓋,選出符合條件的結果重新寫表。1 刪除某個分割槽 alter table table name drop partition dt 2020 09...
ORACLE大表刪除部分資料的最佳方案
今天在統計月對賬時,發現備份庫表中資料比實際資料多出兩千萬行,經查詢發現,原來是同事將某幾天的資料重複備份了。這樣我們本能的考慮刪掉備份重複的那幾天的資料,重新匯入備份,或者本表去重。但是在乙個3億行級的大表中,用delete刪除掉兩千萬行資料,根本是行不通的,delete會產生大量的undo日誌,...
Hive表刪除表部分資料
1 hive表刪除資料不能使用deletefrom table name 中sql語句 2 hive表刪除資料要分為不同的粒度 table partition partition內 alter table table name drop partition partiton name value i...