The simple CASE statement (simple_case_statement) is a syntax element that can be used in a routine to define a database procedure (see CREATE DBPROC Statement), a database function (see CREATE FUNCTION Statement), or a trigger (see CREATE TRIGGER Statement).
<simple_case_statement> ::= CASE
<expression>
<simple_case_when_clause>...
[<case_else_clause>]
END [CASE]
<simple_case_when_clause> ::= WHEN
<literal>[ ...] THEN
<statement>
<case_else_clause> ::= ELSE <statement>
A CASE statement case_statement allows the conditional execution of a statement, dependent on search conditions or the equality of operands.
In the case of a simple CASE statement simple_case_statement, the expression is compared with the literals. If the expression matches a literal, the associated statement is executed and the CASE statement ends.
CASE digit
WHEN 0 THEN toCHAR = 'zero';
WHEN 1 THEN toCHAR = 'one';
WHEN 2 THEN toCHAR = 'two';
WHEN 3 THEN toCHAR = 'three';
WHEN 4 THEN toCHAR = 'four';
WHEN 5 THEN toCHAR = 'five';
WHEN 6 THEN toCHAR = 'six';
WHEN 7 THEN toCHAR = 'seven';
WHEN 8 THEN toCHAR = 'eight';
WHEN 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:
General CASE Statement (searched_case_statement)