1、標准sql規范
一、單個IF 1、 if a=... then ......... end if; 2、 if a=... then ...... else .... end if; 二、多個IF if a=.. then ...... elsif a=.. then .... end if; 這里中間是“ELSIF”,而不是ELSE IF 。這里需要特別注意
2、decode函數
DECODE的語法:
DECODE(value,if1,then1,if2,then2,if3,then3,...,else)
表示如果value等於if1時,DECODE函數的結果返回then1,...,如果不等於任何一個if值,則返回else。
3、case when
case when a='1'then 'xxxx' when a='2' then 'ssss' else
'zzzzz' end as
注意點:
1、以CASE開頭,以END結尾
2、分支中WHEN 后跟條件,THEN為顯示結果
3、ELSE 為除此之外的默認情況,類似於高級語言程序中switch case的default,可以不加
4、END 后跟別名