Entering content frame

General CASE Function (searched_case_function) 

The general CASE function (searched_case_function) is a special function that analyzes a quantity of search conditions to determine a result expression.

Syntax

<searched_case_function> ::=
CASE
  WHEN <search_condition> THEN <result_expression>
    [...]
  [ELSE <default_expression>])
END

<result_expression> ::= <expression>
<default_expression> ::= <expression>

search_condition, expression

Explanation

CASE checks the search conditions (search_condition) in succession. As soon as a search condition that is true is found, the result of the general CASE function is the value of the expression result_expression that belongs to the search condition.

If no true search expression is found, then CASE gets the result of the expression default_expression. If default_expression is not specified, then the result of CASE is NULL.

All search conditions without ROWNO Predicate are permissible. The data types of the expressions result_expression and default_expression must be comparable.

CASE
  WHEN price IS NULL THEN 'Not yet priced'
  WHEN price < 10 THEN 'Very Reasonable Title'
  WHEN price >= 10 and price < 20 THEN 'Coffee Table Title'
  ELSE 'Expensive book!'
END

See also:

Simple CASE function (simple_case_function)

 

Leaving content frame