Selector CASE expression v16
CASE expression attempts to match an expression, called the selector, to the expression specified in one or more
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-expressionis evaluated in the order in which it appears in the
resultis an expression that is type-compatible in the context where the
CASEexpression is used.
- When the first
match-expressionis encountered that equals
resultin the corresponding
THENclause is returned as the value of the
- If none of
- If no
ELSEis specified, the
CASEexpression returns null.
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: