有什么区别not in
and not exists
在 Oracle 查询中?
我什么时候使用not in
? And not exist
?
和...之间的不同NOT IN and 不存在变得清楚哪里有NULL
结果中包含的值。
例如:
create table test_a (col1 varchar2(30 char));
create table test_b (col1 varchar2(30 char));
insert into test_a (col1) values ('a');
insert into test_a (col1) values ('b');
insert into test_a (col1) values ('c');
insert into test_a (col1) values ('d');
insert into test_a (col1) values ('e');
insert into test_b (col1) values ('a');
insert into test_b (col1) values ('b');
insert into test_b (col1) values ('c');
insert into test_b (col1) values (null);
Note: 他们的主要区别在于test_b
包含一个null
value.
select * from test_a where col1 not in (select col1 from test_b);
没有返回行
select * from test_a where
not exists
(select 1 from test_b where test_b.col1 = test_a.col1);
Returns
col1
====
d
e
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)