比如我们有以下表
create table emp as select * from employees;
看看记录数:
select count(*) from emp;
--
107
然后,重复插入几次:
insert into emp select * from emp;
insert into emp select * from emp;
insert into emp select * from emp;
insert into emp select * from emp;
然后看这个emp表中有很多重复记录,
那么我们如何快速删除呢,
我们可以使用oracle的分析函数over partition来处理:
DELETE FROM emp WHERE ROWID IN (SELECT ROWID FROM (SELECT ROWID, ROW_NUMBER() OVER (PARTITION BY employee_id ORDER BY employee_id) rn FROM emp) WHERE rn > 1);
之后,我们再去看,就只有107行记录了.
|