如何在Oracle中删除按名称相关的行

时间:2013-06-19 15:55:56

标签: sql oracle oracle10g

我在数据库表中有以下记录

ID   NAME         REF
-----------------------
1    ar.chik       33
4    ar.chik.rt    33
5    dy.i.op       35
9    dy.i

哪条语句可以删除以下记录:

ID   NAME         REF
------------------------
4    ar.chik.rt    33
5    d.yi.op       35

3 个答案:

答案 0 :(得分:2)

如果您要删除表格中与原始name类似的行,那么您应该可以使用类似于以下内容的内容:

delete 
from yourtable
where id in (select id
             from
             (
               select id, 
                 row_number() over(partition by ref
                                   order by length(name)) rn
               from yourtable
             ) d
             where rn > 1);

请参阅SQL Fiddle with Demo

答案 1 :(得分:1)

如果我理解了你想要的东西,你可以使用它:

DELETE FROM Yourtable WHERE name='ar.chik.rt' OR name='d.yi.op' ;

DELETE FROM Yourtable WHERE name IN ('ar.chik.rt','d.yi.op') ;

或者如果您想要删除多个点的记录:

DELETE FROM Yourtable WHERE name LIKE '%.%.%' ;

答案 2 :(得分:0)

delete from Yourtable 
where id in(4,5);