oracle查询优化系列1

1.1 查找空值

select * from emp where comm is NULL      正确的写法
select * from emp where comm=NULL       错误的写法

1.2 NULL 不支持加、减、乘、除、大小比较、相等比较
1.3 处理空值

  select nvl(comm,0) from emp where nvl(comm,0)>=0  单个空值处理
  select coalesce(c1,c2,c3,c4)  as c from emp 多个空值处理

1.4 查询满足多个条件的行

 在查询条件后面用or关键字,把每一组的条件用括号连起来
 select * from emp where age>12 or score>90 or (sex='1' and class='1')

1.5 为查询返回列取有意义的别名
1.6 在where 子句中引用取别名的列

  select * from (select sal as 工资,comm as 提成 from emp)x where 工资<1000   写报表时候用

1.7 拼接列用 ||
1.8 在select 语句中使用条件逻辑

 select ename,sal,case when sal<=2000 then '过低' when sal>=4000 then '过高' else 'ok' end as status from emp where deptno=10

1.9限制返回的行数

select * from emp where rownum<=2

1.10 以指定次序排序

select empno,ename,age from emp where deptno=10 order by age asc
select empno,ename,age from emp where deptno=10 order by 3 asc  按返回的第三列排序
select empno,deptno,sal,ename from emp order by 2 asc ,3 desc 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值