--去空三剑客
4.coalesce(参1,参2....) 多个参数中第一个不为空的值
select coalesce(null,null,123,null,456)
from dual
--查询提成,经理编号,工资
--以及他们中第一个不为空的值
select comm,mgr,sal,coalesce(comm,mgr,sal)
from emp
去空:coalesce(comm,0)
--查询每位员工每个月的总工资
select sal,comm,sal+coalesce(comm,0)
from emp
5.nvl(参1,参2) 参数1位空返回参数2,否则返回参数1
select nvl(null,0)
from dual
--查询每个人的姓名和他们的月薪
select ename,sal+nvl(comm,0)
from emp
6.nvl2(参1,参2,参3) 参1为空返回参数3,否则返回参数2
select nvl2(null,2,3),nvl2(1,2,3)
from dual
--如果经理编号为空则返回大哥,否则返回小弟
select ename,nvl2(mgr,'小弟','大哥')
from emp
7.distinct 去重
书写位置紧跟着select
select distinct deptno,job
from emp
--查询emp表有几个部门
select distinct deptno
from emp
--查询emp表有几个职位
select distinct job
from emp
--查询emp表有几种部门职位
select distinct deptno,job
from emp
8.case when
(1) case 列 when 列中值1 then 值1
when 列中值2 then 值2
...
[else 值n]
end
select deptno,
case deptno when 10 then '十部门'
when 20 then '二十部门'
else '三十部门'
end A
from emp
--查询员工表的职位,和中文职位
select job,case job when 'CLERK' then '职员'
when 'SALESMAN' then '销售员'
when 'MANAGER' then '经理'
when 'PRESIDENT' then '董事长'
when 'ANALYST' then '分析员'
end 中文职位
from emp
--查询员工表的部门,和中文部门
select dname,case dname when 'ACCOUNTING' then '财务部'
when 'RESEARCH' then '研发部'
when 'SALES' then '销售部'
when 'OPERATIONS' then '营运部'
end 中文部门
from dept<

&spm=1001.2101.3001.5002&articleId=120924049&d=1&t=3&u=677016fbf2ec461a9b81db1447769882)
6420

被折叠的 条评论
为什么被折叠?



