刪除oracle表中名稱重複的記錄

介紹三種方法:

1.建立組合索引

   create index idx_name_id on table(name,id);

   delete from table  a

   where exists(select null from table b

                        where b.name=a.name

                        and b.id>a.id);

2.建立單索引name,用rowid代替id

   delete from table  a

   where exists(select null from table b

                        where b.name=a.name

                        and b.rowid>a.rowid);

3.通過分析函數,根據name分組生成序號,然後刪除序號大於1的數據

   delete from table

   where rowid in(select rid

                           from (select rowid as rid,

                                    row_number() over(partition by name order by id)  as seq

                                    from table)

                            where seq>1);

  

  



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章