DECODE
Purpose
The decode function returns the result
value for which the expression, expr
, matches the expression, search
.
If no match is found, NULL
or − if specified − the default
value is returned.
Syntax
decode::=
Usage Notes
- Decode is similar to CASE, but has slightly different functionality (to be compliant to other databases):
- The expression
expr
can be directly compared with valueNULL
. For example,DECODE(my_column, NULL, 0, my_column)
). - String comparisons are done "non-padded". For example,
DECODE(my_column, 'abc', TRUE, FALSE)
on aCHAR(10)
column always returnsfalse
.
- The expression
- Due to readability reasons we recommend to use CASE.
Example
Result
The result is 2.