在Oracle 10g中使用左连接删除
发布时间:2021-05-22 11:11:51 所属栏目:站长百科 来源:网络整理
导读:我有以下代码在MS SQL Server中工作正常: delete grpfrom grpleft join my_dataon grp.id1 = my_data.id1and grp.id2 = my_data.id2and grp.id3 = my_data.id3and grp.id4 = my_data.id4where my_data.id1 is NULL 基本上,我想删除在grp中可以找到的所有事
我有以下代码在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.id3 = my_data.id3 and grp.id4 = my_data.id4 where my_data.id1 is NULL 基本上,我想删除在grp中可以找到的所有事件,并且在my_data中没有任何等价性.不幸的是,它在Oracle 10g中不起作用.我尝试使用旧的语法左连接(),但它也不工作.喜欢这个: delete grp from grp,my_data where grp.id1 = my_data.id1 (+) and grp.id2 = my_data.id2 (+) and grp.id3 = my_data.id3 (+) and grp.id4 = my_data.id4 (+) and my_data.id1 is NULL 如果我没有多个密钥,但是我看不到如何使用我的数据,则IN子句将起作用.那么什么办法呢? 表格和数据:SQL> create table grp (id1 number null,id2 number null,id3 number null,id4 number null); Table created. SQL> create table my_data (id1 number null,id4 number null); Table created. SQL> insert into grp values (1,2,3,4); 1 row created. SQL> insert into grp values (10,20,30,40); 1 row created. SQL> insert into grp values (1,40); 1 row created. SQL> insert into my_data values (1,4); 1 row created. SQL> commit; Commit complete. 使用in.注意如果子查询中的ID可以为空,请勿使用.不在null不会返回true. SQL> delete grp where (id1,id2,id3,id4) not in (select id1,id4 from my_data); 2 rows deleted. SQL> select * from grp; ID1 ID2 ID3 ID4 ---------- ---------- ---------- ---------- 1 2 3 4 使用存在 SQL> rollback; Rollback complete. SQL> delete grp where not exists (select * from my_data where grp.id1 = my_data.id1 and grp.id2 = my_data.id2 and grp.id3 = my_data.id3 and grp.id4 = my_data.id4); 2 rows deleted. SQL> select * from grp; ID1 ID2 ID3 ID4 ---------- ---------- ---------- ---------- 1 2 3 4 SQL> (编辑:威海站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |