---
title: "删除重复数据的一种高效的方法 "
author: "czllfy"
date: "2007-03-15T20:47:00Z"
tags: ["Oracle", "SQL", "工作"]
slug: "untitled"
draft: true
lastmod: "2007-03-15T20:47:00Z"
id: 60142
url: "https://czllfy.iteye.com/blog/60142"
---

表demo是重复拷贝自dba\_objects，有88万左右，不重复的是27323，没有索引  
方法一：delete from demo a where a.rowid &lt;&gt; (select max(rowid) from demo b where  
b.object\_id=a.object\_id);  
耗时：几个小时以上

方法二： delete from demo where rowid in  
(select rid from  
(select rowid rid,row\_number() over(partition by object\_id order by rowid) rn  
from demo)  
where rn &lt;&gt; 1 );  
耗时：30秒

方法三： create table demo2 as  
select object\_id,owner... from  
(select demo.\*,row\_number() over(partition by object\_id order by rowid) rn from demo)  
where rn = 1;  
truncate table demo; insert into demo select * from demo2; drop table demo2;  
共耗时： 10秒，适合大数据量的情况，产生更少回滚量；