This article brings you relevant knowledge aboutOracle, which mainly introduces the duplicate data in the table that is often cleared during data cleaning. So how to deal with it in Oracle? Let’s take a look at it together, I hope it will be helpful to everyone.

Recommended tutorial: "Oracle Video Tutorial"
create table nayi224_180824(col_1 varchar2(10), col_2 varchar2(10), col_3 varchar2(10)); insert into nayi224_180824 select 1, 2, 3 from dual union all select 1, 2, 3 from dual union all select 5, 2, 3 from dual union all select 10, 20, 30 from dual ; commit; select*from nayi224_180824;
| COL_1 | COL_2 | COL_3 |
|---|---|---|
| 1 | 2 | 3 |
| 1 | 2 | 3 |
| 5 | 2 | 3 |
| 10 | 20 | 30 |
select distinct t1.* from nayi224_180824 t1;
| COL_2 | COL_3 | |
|---|---|---|
| 20 | 30 | |
| 2 | 3 | |
| 2 | 3 |
select distinct t1.col_2, col_3 from nayi224_180824 t1
| COL_3 | |
|---|---|
| 3 | |
| 30 |
row_number()
select * from (select t1.*, row_number() over(partition by t1.col_2, t1.col_3 order by 1) rn from nayi224_180824 t1) t1 where t1.rn = 1 ;
| COL_2 | COL_3 | RN | |
|---|---|---|---|
| 2 | 3 | 1 | |
| 20 | 30 | 1 |
select * from nayi224_180824 t where (t.col_2, t.col_3) in (select t1.col_2, t1.col_3 from nayi224_180824 t1 group by t1.col_2, t1.col_3 having count(1) > 1)
| COL_3 | ||
|---|---|---|
| 3 | 1 | |
| 3 | 5 | |
| 3 |
select * from (select t1.*, count(1) over(partition by t1.col_2, t1.col_3) rn from nayi224_180824 t1) t1 where t1.rn > 1 ;
| COL_3 | RN | ||
|---|---|---|---|
| 3 | 3 | 1 | |
| 3 | 3 | 5 | |
| 3 | 3 |
delete from nayi224_180824 t where t.rowid in ( select rid from (select t1.rowid rid, count(1) over(partition by t1.col_2, t1.col_3) rn from nayi224_180824 t1) t1 where t1.rn > 1);
delete from nayi224_180824 t where t.rowid in (select rid from (select t1.rowid rid, row_number() over(partition by t1.col_2, t1.col_3 order by 1) rn from nayi224_180824 t1) t1 where t1.rn > 1);
delete from nayi224_180824 t where t.rowid not in (select max(rowid) from nayi224_180824 t1 group by t1.col_2, t1.col_3);
Oracle Video Tutorial
"The above is the detailed content of Summarize and organize common methods for removing duplicate data from Oracle database. For more information, please follow other related articles on the PHP Chinese website!