The general CASE statement (searched_case_statement) is a syntax element that is used in a statement. You can use the general CASE statement to define a database procedure (see CREATE DBPROC statement) or a trigger (see CREATE TRIGGER statement).
Syntax
<searched_case_statement> ::= CASE
<searched_case_when_clause>...
[<case_else_clause>]
END [CASE]
<searched_case_when_clause> ::= WHEN
<search_condition> THEN <statement>
<case_else_clause> ::= ELSE <statement>
Explanation
Variables specified in a routine can be assigned a value with a statement.
Control Structures
A CASE statement (case_statement) allows the conditional execution of a statement, dependent on search conditions or the equality of operators.
In the case of a general CASE statement (searched_case_statement), the first fulfilled search condition is determined, the associated statement executed, and the CASE statement ends.
CASE
WHEN digit = 0 THEN toCHAR = 'zero';
WHEN digit = 1 THEN toCHAR = 'one';
WHEN digit = 2 THEN toCHAR = 'two';
WHEN digit = 3 THEN toCHAR = 'three';
WHEN digit = 4 THEN toCHAR = 'four';
WHEN digit = 5 THEN toCHAR = 'five';
WHEN digit = 6 THEN toCHAR = 'six';
WHEN digit = 7 THEN toCHAR = 'seven';
WHEN digit = 8 THEN toCHAR = 'eight';
WHEN digit = 9 THEN toCHAR = 'nine';
ELSE STOP(-29000, 'no digit');
END CASE
In a CASE statement, if no matching literal or fulfilled search condition exists, the statement in the ELSE branch is executed.
If there is no ELSE branch, runtime error -28901 is returned.
See also:
Simple CASE statement (simple_case_statement)