The selector CASE statement attempts to match an expression called the selector to the expression specified in one or more WHEN clauses. When a match is found, one or more corresponding statements are executed.
selector-expression returns a value type-compatible with each match-expression.
match-expression is evaluated in the order in which it appears in the CASE statement.
statements are one or more SPL statements, each terminated by a semi-colon.
When the value of selector-expression equals the first match-expression, the statements in the corresponding THEN clause are executed, and control continues following the END CASE keywords.
If there are no matches, the statements following ELSE are executed.
If there are no matches and there is no ELSE clause, an exception is thrown.
This example uses a selector CASE statement to assign a department name and location to a variable based on the department number: