Selector CASE Expression v13
The selector CASE
expression attempts to match an expression called the selector to the expression specified in one or more WHEN
clauses. result
is an expression that is type-compatible in the context where the CASE
expression is used. If a match is found, the value given in the corresponding THEN
clause is returned by the CASE
expression. If there are no matches, the value following ELSE
is returned. If ELSE
is omitted, the CASE
expression returns null.
match-expression
is evaluated in the order in which it appears within the CASE
expression. result
is an expression that is type-compatible in the context where the CASE
expression is used. When the first match-expression
is encountered that equals selector-expression
, result
in the corresponding THEN
clause is returned as the value of the CASE
expression. If none of match-expression
equals selector-expression
then result
following ELSE
is returned. If no ELSE
is specified, the CASE
expression returns null.
The following example uses a selector CASE
expression to assign the department name to a variable based upon the department number.
The following is the output from this program.