Home >Database >Mysql Tutorial >Oracle比较快的删除重复数据的方式

Oracle比较快的删除重复数据的方式

WBOY
WBOYOriginal
2016-06-07 17:28:29833browse

网上五花八门,Oracle删除重复数据的方法就是没见过这种: DELETE FROM prod_grid_inc WHERE ROWID IN (SELECT b.row_id2

网上五花八门,Oracle删除重复数据的方法就是没见过这种:
 

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);
 大家不妨试试,经过试验,的确快了不少。

如果是几G的大表(这种时候一般是分区表),这种情况最好是append+nologging方式,将唯一记录insert到临时表中,然后通过交换分区的方式交换过去,,前后只需要几分钟,其中临时表的表空间和索引表空间要符合正式表的要求:

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;
 当然exchange的方式虽然快,但是这种情况会导致索引失效,需要重建索引:
 

alter index ind_name rebuild subpartition subpartition_name;
 如此即可。

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn