好比咱們有如下表oracle
create table emp as select * from employees;函數
看看記錄數:3d
select count(*) from emp;blog
--get
107it
而後,重複插入幾回:io
insert into emp select * from emp;table
insert into emp select * from emp;select
insert into emp select * from emp;channel
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行記錄了.