注意事项: Oracle Not Exists 及 Not In 使用
2013-07-13 23:13
429 查看
select value from temp_a a
where a.id between 1 and 100
and not exists(select * from temp_b b where a.value=b.value);
这时能查出结果
select value from temp_a a
where a.id between 1 and 100
and a.value not in(select value from temp_b);
此时查出的结果为空.
经过google终于找出原因: 内表(temp_b)有空值. 用not in得到的结果集都为空.以下是结论:
1、对于not exists查询,内表存在空值对查询结果没有影响;对于not in查询,内表存在空值将导致最终的查询结果为空。
2、对于not exists查询,外表存在空值,存在空值的那条记录最终会输出;对于not in查询,外表存在空值,存在空值的那条记录最终将被过滤,其他数据不受影响。
where a.id between 1 and 100
and not exists(select * from temp_b b where a.value=b.value);
这时能查出结果
select value from temp_a a
where a.id between 1 and 100
and a.value not in(select value from temp_b);
此时查出的结果为空.
经过google终于找出原因: 内表(temp_b)有空值. 用not in得到的结果集都为空.以下是结论:
1、对于not exists查询,内表存在空值对查询结果没有影响;对于not in查询,内表存在空值将导致最终的查询结果为空。
2、对于not exists查询,外表存在空值,存在空值的那条记录最终会输出;对于not in查询,外表存在空值,存在空值的那条记录最终将被过滤,其他数据不受影响。
相关文章推荐
- 注意事项: Oracle Not Exists 及 Not In 使用
- 【转】Oracle Outline使用方法及注意事项
- 使用Oracle中的用户表作为Openfire用户系统(注意事项记录)
- 在oracle中字段类型LONG的使用注意事项
- Oracle的LOGMNR工具的使用及注意事项
- Linux 和 oracle使用时需要注意的事项
- 使用oracle utl_http包需要注意的事项
- linux nfs服务配置挂载以及oracle使用nfs存储挂载注意事项
- (转)oracle group by 和order by的关系(在一起使用注意事项)
- Oracle8的OCI函数中参数使用的注意事项
- Oracle 数据类型使用注意事项
- ls使用ODBC连接Oracle注意的事项
- Oracle rebuild index 使用 parallel 时 与 并行度 的注意事项
- Oracle在windows上的使用注意事项
- Oracle Data Provider for .NET的使用(二)-驱动更换与注意事项
- 32位和64位C++程序使用ADO访问ORACLE注意事项和区别
- Oracle Data Pump使用范例及部分注意事项(expdp/impdp)
- 转:Oracle Outline的使用及注意事项
- oracle中的not in注意事项
- 在oracle中字段类型LONG的使用注意事项