今天下班前,突然接到局方電話,要求提供10月詳單通話記錄。
這下就開始整,結果不小心,把提取的記錄全部插入到了詳單表。這下好了,幾十w條重複記錄,在1000億大表中,刪除嘛。
--下面是解決方案:
--1.找出提交值 ora_rowscn
-- select scn_to_timestamp(ora_rowscn) from dual 查看提交時間
select /*+ parallel(12) */ dt.ora_rowscn,count(*) from table_name(涉及隱私) dt, table_b(涉及隱私) cp
where dt.starttime>=to_date('2013-10-05 00:00:00','yyyy-mm-dd hh24:mi:ss')
and dt.starttime<to_date('2013-10-06 00:00:00','yyyy-mm-dd hh24:mi:ss')
and dt.called in ('123456','xxxxx')
and substr(dt.caller,1,3) in ('..','..','....')
and dt.xxx=cp.xx
and cp.ldcflag=1
--and dt.ora_rowscn=31902278734
group by dt.ora_rowscn
order by 2 desc
;
--
--驗證時間
select scn_to_timestamp(31903242189) from dual
--驗證條數
--select 10910+1841 from dual
--建立表
create table rowid_4 as
select rowid rowids from table_name (涉及隱私) dt
where dt.starttime>=to_date('2013-10-04 00:00:00','yyyy-mm-dd hh24:mi:ss')
and dt.starttime<to_date('2013-10-05 00:00:00','yyyy-mm-dd hh24:mi:ss')
and dt.ora_rowscn in (31901488022,31905491128)
--驗證條數
select count(*) from rowid_4;
--根據rowid重複資料刪除資料
delete /*+ parallel(8) nologging use_hash(dt ssd )*/ from table_name (涉及隱私) dt
where dt.rowid in (select rowids from rowid_4 ssd)