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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM