oracle中if else功能的實現的3種寫法

2021-07-08 15:26:50 字數 865 閱讀 5424

1、標準sql規範

一、單個if

1

if a=... then

.........

endif

;2

if a=... then

......

else

....

endif

;二、多個if

if a=.. then

......

elsif a

=.. then

....

endif

;

這裡中間是「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 '***x'

when a='2

'then 'ssss'

else

'zzzzz'

endas

注意點: 

1、以case開頭,以end結尾 

2、分支中when 後跟條件,then為顯示結果 

3、else 為除此之外的預設情況,類似於高階語言程式中switch case的default,可以不加 

4、end 後跟別名  

oracle中if else功能的實現

一 單個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 val...

oracle中if else功能的實現的3種寫法

經常會用到的,記錄一下 1.case when case when a 1 then aaa when a 2 then bbb else ccc end as name 注意點 1 以case開頭,以end結尾 2 分支中when 後跟條件,then為顯示結果 3 else 為除此之外的預設情況,...

oracle中if else功能的實現的3種寫法

1 標準sql規範 一 單個if 1 if a then endif 2 if a then else endif 二 多個if if a then elsif a then endif 這裡中間是 elsif 而不是else if 這裡需要特別注意 2 decode函式 decode的語法 dec...