2009/04/15

Case

example : (與使用Decode雷同)
select 
case to_char(sysdate,'DD')
  when '1' then '星期日'
  when '2' then '星期一'
  when '3' then '星期二'
  when '4' then '星期三'
  when '5' then '星期四'
  when '6' then '星期五'
  when '7' then '星期六'
  else '錯誤'
end case
from dual 

example : (比Decode方式多了判斷條件)
select 
case 
    when to_char(sysdate,'Q') > 2 then 
    '下半年'
    else
    '上半年'
end case    
from dual 
 
總結 : 
1. 使用Case 與 Decode 方式效能是差不多的(60萬筆資料查詢,使用Case是快了點)
2. 若有判斷條件,還是使用Case為是


沒有留言: