--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