Show TOC

Function documentationDECODE(x,y(i),...,z) Locate this document in the navigation structure

 

DECODE(x,y(i),...,z) is a special function which decodes expressions in accordance with their values.

DECODE(x,y(i),...,z)

x

check_expression

Expression (expression) for which a comparison is to be carried out with the comparison values y(i)

y(i)

search_and_result_spec

<search_and_result_spec> ::= <search_expression>, <result_expression> (Short form: y(i)=u(i),v(i), i=1,...)

Combination of the comparison value u(i) and the value v(i) that is to replace this comparison value

z

default_expression

Optional default value (LOB value is permissible)

u(i)

search_expression

Comparison value that is to be replaced by v(i) if it matches x

v(i)

result_expression

Value that is to replace the value u(i), if necessary (LOB value is permissible)

The data types of x and u(i) must be comparable. The data types of v(i) and z must be comparable. The data types of u(i) and v(i) do not have to be comparable.

DECODE compares the values of x with the values u(i) consecutively. If values match, the result of DECODE is the value v(i) in the combination y(i)=u(i),v(i).

If x and u(i) are NULL values, then a match exists. The comparison of the special NULL value with any other value never results in a match. If no match is found, DECODE returns the result of z. If z is not specified, the result of DECODE is the NULL value.

Example

SQL Tutorial, Converting Values