一件簡單的事情做的就是這樣的事情
delete /*+RULE*/ from t
where rowid in (select rid
from (select rowid rid,
row_number() over
(partition by cust_seg_nbr order by rowid) rn
from t
)
where rn <> 1);
不過,如果你有大量的數據,然後
檢查此鏈接http://www.rampant-books.com/t_stoever_delete_duplicates.htm或者使用下面
DECLARE -- Code ©2004 by Edward Stoever
CURSOR c_get_duplicates
IS
SELECT ssrfees_term_code, ssrfees_crn, ssrfees_detl_code,
ssrfees_ftyp_code, ssrfees_levl_code, COUNT (*)
FROM ssrfees
HAVING COUNT (*) > 1
GROUP BY ssrfees_term_code,
ssrfees_crn,
ssrfees_detl_code,
ssrfees_ftyp_code,
ssrfees_levl_code;
var_get_duplicates c_get_duplicates%ROWTYPE;
CURSOR c_del_only_one
IS
SELECT ROWID
FROM ssrfees
WHERE ssrfees_term_code = var_get_duplicates.ssrfees_term_code
AND ssrfees_crn = var_get_duplicates.ssrfees_crn
AND ssrfees_detl_code = var_get_duplicates.ssrfees_detl_code
AND NVL(ssrfees_ftyp_code,'1') = NVL(var_get_duplicates.ssrfees_ftyp_code,'1')
AND NVL(ssrfees_levl_code,'1') = NVL(var_get_duplicates.ssrfees_levl_code,'1');
var_del_only_one ROWID;
BEGIN
OPEN c_get_duplicates;
LOOP
FETCH c_get_duplicates
INTO var_get_duplicates;
EXIT WHEN c_get_duplicates%NOTFOUND;
OPEN c_del_only_one;
FETCH c_del_only_one
INTO var_del_only_one;
DELETE FROM ssrfees
WHERE ROWID = var_del_only_one;
COMMIT;
CLOSE c_del_only_one;
END LOOP;
CLOSE c_get_duplicates;
END;
/
真的很重要嗎?你一定會這樣做,並且2分鐘去除120萬個副本似乎是相當合理的。 – 2012-07-25 13:33:18
嗨託尼,感謝您的快速響應。這是遷移的一部分,它將在每次從樣本轉儲設置新數據庫時執行。 – Anand 2012-07-25 15:42:45
除了解決方案,我更有興趣瞭解是否可以使用類型,批量收集或可能並行pl/sql優化它? – Anand 2012-07-25 16:00:32