注意事项: Oracle Not Exists 及 Not In 使用
2015-12-03 11:30
435 查看
今天遇到一个问题,not in 查询失效,我以为是穿越了,仔细查了点资料,原来理解有误!
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查询,外表存在空值,存在空值的那条记录最终将被过滤,其他数据不受影响。
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查询,外表存在空值,存在空值的那条记录最终将被过滤,其他数据不受影响。
相关文章推荐
- Oracle字符串操作函数(CONCAT,REPLACE,SUBSTR ....)
- [Oracle]行内聚合大小函数 Greatest and Least
- ORA-01767: UPDATE ...SET 表达式必须是子查询
- 完全卸载oracle11g步骤
- linux oracle 创建表空间,用户,赋权限
- Oracle的书写规范和优化建议
- oracle 账号管理
- 关于oracle中to_char的用法
- 转 -- ORACLE Checkpoint(检查点)
- 随身小记:oracle保留两位小数、小数点后不足两位的补.00。
- 随身小记:ORA-01722无效数字的解决办法
- Oracle查看当前实例及版本、字符集
- oracle数据库数据量较大时更新数据较慢问题
- Oracle常用函数
- db2像oracle一样使用hints(guidelines)
- oracle 触发器number判断空值,:NEW赋值,for each row,sql变量引号,to_date,to_char
- Oracle的10046事件
- ORACLE创建表空间、创建用户以及赋值权限
- oracle dbconsole 因为IP改动启动不了,重建方式
- oracle中的检查点Ckpt和SCN号