Oracle 条件判断函数decode和case when then案例

--decode条件判断函数
select decode(100,150,200,300,400,-1) from dual
--需求:不通过连表查询,显示业主类型名称列的值
select name,decode(ownertypeid,1,'居民',2,'事业单位',3,'商业','其他')
from t_owners
--case when then写法
select name,(
       case ownertypeid
       when 1 then '居民'
       when 2 then '事业单位'
       when 3 then '商业'
       else '其他'
       end
)from t_owners
--case when then 相对灵活的写法
select name,(
       case 
       when ownertypeid=1 then '居民'
       when ownertypeid=2 then '事业单位'
       when ownertypeid=3 then '商业'
       else '其他'
       end
)from t_owners


select * from t_owners o,t_ownertype p where o.ownertypeid=p.id

 

posted @ 2018-11-21 20:23  学亮编程手记  阅读(4557)  评论(0编辑  收藏  举报