DECODE(criteria_exp, compare1_exp, return1_exp, compare2_exp, return2_exp,...,[default_return_exp])

Returns return#_exp if criteria_exp evaluates to compare#_exp, or possibly default_return_exp if there are no matches.  If the criteria_exp does not match any of the compare expressions, then the default_return_exp will be return if supplied.  If the criteria_exp does not match any of the compare expressions and the default_return_exp was not specified, NULL is returned.

 

Note:  DECODE and SWITCH are synonyms; you can use either function and get the same results.

 

Example:

Select Decode(2, 1, 'YES', 2, 'NO', 3, 'POSSIBLY')  

Returns: NO

 

Example:

Select Decode(3, 1, 'YES', 2, 'NO', 3, 'POSSIBLY')

Returns: POSSIBLY

 

Example:

Select Decode(20, 1, 'YES', 2, 'NO', 3, 'POSSIBLY', 'UNKNOWN' )

Returns: UNKNOWN