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