網(wǎng)上五花八門(mén)刪除重復(fù)數(shù)據(jù)的方法就是沒(méi)見(jiàn)過(guò)這種:
DELETE FROM prod_grid_inc
WHERE ROWID IN (SELECT b.row_id2
FROM (SELECT ROWID row_id2,
a.*,
row_number() over(PARTITION BY a.prod_id ORDER BY a.insert_date DESC) row_num
FROM prod_grid_inc a) b
WHERE b.row_num >= 2);
大家不妨試試,經(jīng)過(guò)試驗(yàn),的確快了不少。
如果是幾G的大表(這種時(shí)候一般是分區(qū)表),這種情況最好是append+nologging方式,將唯一記錄insert到臨時(shí)表中,然后通過(guò)交換分區(qū)的方式交換過(guò)去,前后只需要幾分鐘,其中臨時(shí)表的表空間和索引表空間要符合正式表的要求:
eg:
INSERT /*+append*/ INTO ACCT_ITEM_MID
SELECT *
FROM ACCT_ITEM SUBPARTITION(P_201109_SUB_P_XX) a
WHERE ROWID = (SELECT MAX(ROWID)
FROM ACCT_ITEM SUBPARTITION(P_201109_SUB_P_XX) a1
WHERE a.cust_id = a1.cust_id);
COMMIT;
ALTER TABLE ACCT_ITEM EXCHANGE SUBPARTITION P_201109_SUB_P_XX WITH TABLE ACCT_ITEM_MID;
當(dāng)然exchange的方式雖然快,但是這種情況會(huì)導(dǎo)致索引失效,需要重建索引:
alter index ind_name rebuild subpartition subpartition_name;
如此即可。
更多信息請(qǐng)查看IT技術(shù)專(zhuān)欄