SWITCH(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 Switch(2, 1, 'YES', 2, 'NO', 3, 'POSSIBLY')  

Returns: NO

 

Example:

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

Returns: POSSIBLY

 

Example:

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

Returns: UNKNOWN