Simple CASE Statement (simple_case_statement)
The simple CASE statement (
simple_case_statement) is a syntax element that is used in a statement. You can use the simple CASE statement to define a database procedure (see CREATE DBPROC statement) or a trigger (see CREATE TRIGGER statement).Syntax
<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>
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 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)