- Categories:
NVL2¶
Returns values depending on whether the first input is NULL:
If
expr1is NOT NULL, then NVL2 returnsexpr2.If
expr1is NULL, then NVL2 returnsexpr3.
Syntax¶
NVL2( <expr1> , <expr2> , <expr3> )
Arguments¶
expr1The expression to be checked to see whether it is NULL.
expr2If
expr1is not NULL, this expression will be evaluated and its value will be returned.expr3If
expr1is NULL, this expression will be evaluated and its value will be returned.
Usage notes¶
All three expressions should have the same (or compatible) data type.
Collation details¶
The collation specification for
expr1is ignored because all that matters about this expression is whether it is NULL or not.The collation specifications for
expr2andexpr3must be compatible.The value returned from the function is the highest-precedence collation of
expr2andexpr3.
Examples¶
If a is not null, then return b, else return c:
SELECT a, b, c, NVL2(a, b, c) FROM i2; --------+--------+--------+---------------+ A | B | C | NVL2(A, B, C) | --------+--------+--------+---------------+ 0 | 5 | 3 | 5 | 0 | 5 | [NULL] | 5 | 0 | [NULL] | 3 | [NULL] | 0 | [NULL] | [NULL] | [NULL] | [NULL] | 5 | 3 | 3 | [NULL] | 5 | [NULL] | [NULL] | [NULL] | [NULL] | 3 | 3 | [NULL] | [NULL] | [NULL] | [NULL] | --------+--------+--------+---------------+