高效快速刪除Oracle表中重復(fù)記錄

字號(hào):


    以前的一篇?jiǎng)h除重復(fù)記錄的雖然還不錯(cuò) 但是在我遇到重量級(jí)的大表時(shí)還是顯的力不從心,不小心想到一種新的方法
    思路1、保存不重復(fù)的記錄
    2、保存重復(fù)記錄中的一個(gè)rowid
    //3、刪除原表中rowid不為步驟2中rowid的記錄 ,留下重復(fù)數(shù)據(jù)中的一條
    3.找出記錄中rowid為步驟2中rowid的記錄
    4 、1和3數(shù)據(jù)連接就是所要的數(shù)據(jù)了
    具體操作例子
    第一步:www.examw.com
    SQL> create table xxfgs_sig as (select imeid imeid,max(dn) dn,max(xlh) xlh,max(pro_name) pro_name,max(area_name) area_na
    me,max(brand) brand,max(m_type) m_type from xxfgs group by imeid having count(*)<2);
    第二步:
    SQL> create table xxfgs_row as (select max(rowid) rowdata,imeid from xxfgs group by imeid having count(*)>1);
    //第三步:////可以考慮給meid建索引
    //SQL>delete from xxfgs where rowid not in (select rowdata from xxfgs_row);
    //或者
    //SQL>delete from xxfgs a where a.rowid <>(select rowdata from xxgs_row b where a.meid=b.meid)。