Syntax
The CASE expression comes in two forms:- Simple CASE
expression is compared to each expression in the WHEN clause. If an equal expression is found, the result in the THEN clause is returned. If no equal expression is found, the result in the ELSE clause is returned if ELSE is present.
- Searched CASE
Parameters
-
expressionN: the expression to compare. Multiple expressions must be compatible in data types. -
conditionN: the condition that can evaluate to a BOOLEAN value. -
resultNmust be compatible in data types.
Return value
The return value is of the common type of all types in the THEN clause.Examples
Suppose tabletest_case has the following data:
Use simple CASE
- ELSE is specified and the result in ELSE is returned if no equal expression is found.
- ELSE is not specified and NULL is returned if no condition evaluates to true.