Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to delete the same record in the oracle library

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

How to delete the same record in the oracle library, but keep a record in a duplicate record:

Solution: you can use the rowid pseudo-column in oracle to do this:

1. Create a temporary table and insert the duplicate data from the query (can I create a view?) :

Create table temp_woods as

(select item_id,count (*) as rowcount from wooods group by item_id having count (*) > 1)

two。 Query the same record:

Select A. from woods b where b.item_id in. Rowid from woods a where a.rowid (select max (b.rowid) from woods b where b.item_id in (select item_id from temp_woods) where b.item_id = a.item_id)

3. Delete duplicate records and keep the record with the largest rowid column:

Delete from woods a where a.rowid (select max (b.rowid) from woods b where b.item_id in (select item_id from temp_woods) where b.item_id = a.item_id)

4. Delete temporary tables:

Drop table temp_woods cascade constraints

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report