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 value NULL . For example, DECODE(my_column, NULL, 0, my_column)).
- String comparisons are done "non-padded". For example, DECODE(my_column, 'abc', TRUE, FALSE) on a CHAR(10) column always returns false.
- Due to readability reasons we recommend to use CASE.
Example
Result
The result is 2.