oracle中is not null,oracle之is null和is not null的优化「建议收藏」
oracle之优化is null语句
一:is null的优化
方法:通过nvl(字段,j)=j的方式,将字段中为空的数据转化为j,从而正常使用索引。
具体实现条件则是:i is null <===> j = nvl(i,j);
注意:使用时必须要确保字段的数据不包含j,例如:(age,15)=15,此时有可能age
内容是15,此时不可以,j的值要变换,保证不再age的范围之内。
函数介绍:
nvl(a,b,c…….):当a为空时取b,当b为空时取c,以此类推。
当然还有另外一种方式解决这个问题:将null包含到索引中
–使用nvl函数的方式(不用添加索引,推荐)
select * from student t where 1=nvl(t.age,1);
–当t.age不存在等于1的数据时等价于
–select * from student t where t.age is null;
–添加索引的方式
create index idx_age_x on tab_i(decode(age,null,1));
select * from student t where decode(t.age,null,1)=1;
二:is not null的优化
方法:结果集不包含j = nvl(i,j)即可
通常情况下使用not exists或者比较大小
示例:
1:not exists
select * from student t where not exists
(select 1 form student s where 1=nvl(s.age,1));
–11g版本后not in和not exists趋于相似,也可以用not in
–当t.col_x不存在等于1的数据时等价于
–select * from student t where t.age is not null;
2:比较大小
–当t.age为总是大于1的数值时
select * from student t where 1
–当t.age为总是小于1的数值时
select * from student t where 1>nvl(t.age,1);
–直接比较大小,暗含了 IS NOT NULL
select * from student t where t.age>1;
3:比较长度
–当t.age的长度总是大于1时
select * from student t where 2<=length(nvl(t.age,1));
–因为length函数的参数为空时,其结果为空,因而不能直接使用length函数
参考链接:
https://blog.csdn.net/qq_38880340/article/details/84290900
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/179178.html原文链接:https://javaforall.cn
相关文章
- 简易Oracle命令操作指南(oracle命令操作)
- 查询Oracle记录查询实战:精通数据分析技能(oracle记录)
- 深入了解Oracle日志文件路径(oracle日志文件路径)
- 份Oracle 时间累加月份算法(oracle时间加月)
- 查询优化Oracle中IN查询的技巧(oracle优化in)
- Oracle数据库的高性能SQL优化技术(oracle高性能sql)
- Oracle触发器的种类简介(oracle触发器类型)
- Oracle中如何查询序列的方法(oracle如何查询序列)
- 64位系统上,全新体验Oracle带来的惊喜(64位系统的oracle)
- 双重授权Oracle的终极保障(dual授权oracle)
- Oracle临时表空间优化6个实用方法(oracle临时表空间6)
- 使用Oracle交换分区命令实现数据优化(oracle交换分区命令)
- 性如何借助Oracle修改列的非空性(oracle 修改列非空)
- Oracle事务拆分实现数据安全可靠(oracle事务分割)
- Oracle 数据库优化之道使用分区表(oracle 使用分区表)
- Oracle优化助力企业数据处理提速(oracle优化 百度云)
- Oracle中利用表分区实现管理的优化(oracle中建表的分区)
- 不用密码,Oracle瞬间登录(oracle不输密码登录)
- Oracle中绕过函数索引的优化方案(oracle不走函数索引)
- Oracle三表联合查询分页的实现(oracle三表分页)
- Oracle NFS参数优化,提升性能(oracle nfs参数)
- Oracle ECO配置永恒的环境友好之旅(oracle eco配置)
- 模式Oracle 11倾心完美打造精简模式(oracle 11精简)