Background documentationGeneral CASE Function (searched_case_function) Locate this document in the navigation structure

 

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

Structure

Syntax Syntax

  1. <searched_case_function> ::=
      CASE
        WHEN <search_condition> THEN <result_expression>
        [...]
        [ELSE <default_expression>]
      END
    
    <result_expression>::=
      <expression>
    
    <default_expression>::=
      <expression>
End of the code.
Examples

SQL Tutorial, Functions

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, the result of CASE is the NULL value.

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