Delete with Left Join in Oracle 10g

前端 未结 5 1779
臣服心动
臣服心动 2020-12-05 19:33

I have the following code that works fine in MS SQL Server:

delete grp
from grp
left join my_data
on grp.id1 = my_data.id1
and grp.id2 = my_data.id2
and grp.         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-05 20:01

    I can't add a comment because it need 50 reps,so I add a answer here.

    I tested Vincent's delete from query, that syntax can't let you delete what you want,at least it's not a common use for all the delete join cases.

    At first I create a table using oracle default user scott:

    create table emp1 as select * from emp where sal<2000;
    

    I want to delete the records from emp where empno in emp1(just a simple test),so I used this delete from query:

    delete from (select a.* from emp a join emp1 b on a.empno=b.empno);
    

    No matter what the table or join order is,left join or inner join,no matter what where clause I use,the sql will delete the corresponding records in emp1.

    So I think this delete from query can not let you delete from a specified table. Loop a cursor will be a better way for these cases.

提交回复
热议问题