Entering content frame

Simple CASE Statement (simple_case_statement) Locate the document in the library structure

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[EDURE] statement), a database function (CREATE FUNCTION 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

A case_statement allows the conditional execution of a statement depending on search conditions or equality of operands.

In the case of a 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.

Example

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

If no matching literal or fulfilled search condition exists in a CASE statement, the statement in the ELSE branch is executed.

If there is no ELSE branch, the runtime error -28901 is returned.

See also:

General CASE Statement (searched_case_statement)

 

Leaving content frame