首頁  >  文章  >  資料庫  >  Oracle怎麼查詢重複字段

Oracle怎麼查詢重複字段

WBOY
WBOY原創
2022-01-21 11:41:338025瀏覽

在Oracle中,可以利用count()函數來查詢重複字段,語法為「select * from 表名where 字段in(select 字段from 表名group by 字段having count(字段) >1) 」。

Oracle怎麼查詢重複字段

本教學操作環境:Windows10系統、Oracle 11g版、Dell G3電腦。

Oracle怎麼查詢重複欄位

1、查找表中多餘的重複記錄,重複記錄是根據單一欄位(userCode)來判斷

select 
* 
from 
user
where 
userCode
in 
(select  userCode  from  user group by  userCode having count (userCode) > 1)

2、刪除表中多餘的重複記錄,重複記錄是根據單一欄位(userCode)來判斷,只留有rowid最小的記錄

delete from 
user 
where 
userCode 
in 
(select userCode from user group by  userCode having count (peopleId) > 1)
and rowid not in 
(select min(rowid) from   user group by userCode having count(userCode)>1)

3、查找表中多餘的重複記錄(多個欄位)

select 
* 
from 
user a
where 
(a.userCode,a.userName) 
in  
(select userCode,userName from user group by userCode,userName having count(*) > 1)

4、刪除表中多餘的重複記錄(多個欄位),只留有rowid最小的記錄

delete from 
user a
where
(a.userCode,a.userName) 
in   
(select userCode,userName from user group by userCode,userName having count(*) > 1)
and rowid not in 
(select min(rowid) from user group by userCode,userName having count(*)>1)

5、查找表中多餘的重複記錄(多個欄位),不包含rowid最小的記錄

select 
* 
from 
user a
where 
(a.userCode,a.userName)  
in   
(select userCode,userName from user group by userCode,userName having count(*) > 1)
and rowid not in 
(select min(rowid) from user group by userCode,userName having count(*)>1)

推薦教學:《Oracle教學

以上是Oracle怎麼查詢重複字段的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn