Selector CASE expression v17
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.
Syntax
match-expression
is evaluated in the order in which it appears in theCASE
expression.result
is an expression that is type-compatible in the context where theCASE
expression is used.- When the first
match-expression
is encountered that equalsselector-expression
,result
in the correspondingTHEN
clause is returned as the value of theCASE
expression. - If none of
match-expression
equalsselector-expression
, thenresult
followingELSE
is returned. - If no
ELSE
is specified, theCASE
expression returns null.
Example
This example uses a selector CASE
expression to assign the department name to a variable based on the department number:
The following is the output from this program: