Decode 語法
SELECT DECODE( 欲判斷的資料, 判斷值1, 相等的設定值1 , 判斷值2, 相等的設定值2 , ... , 不相等的設定值 ) FROM ...;
Decode 範例
SELECT DECODE( &DATA, '100', 'AAA' , '200', 'BBB' , '300', 'CCC' , '400', 'DDD' , 'NONE' ) FROM DUAL;
Case 語法
SELECT Case When (判斷式1) Then 設定值1 When (判斷式2) Then 設定值2 ... Else 其他設定值 End 自訂Case_Name FROM ...;
Case 範例
SELECT col1 , CASE WHEN ( col1=0 ) then 'A' WHEN ( col1 in (1,2) ) then 'B' WHEN ( col1 between 3 and 5 ) then 'C' WHEN ( col1 > 5 ) then (select '1' from dual) ELSE 'XYZ' END case_col1 FROM temp;