Categories:

Conditional Expression Functions

# IFNULL¶

If expr1 is NULL, returns expr2, otherwise returns expr1.

Aliases

NVL

## Syntax¶

IFNULL( <expr1> , <expr2> )


## Arguments¶

expr1

A general expression.

expr2

A general expression.

## Usage Notes¶

• If possible, pass in arguments of the same type. Avoid passing in arguments of different types.

• If one of the arguments is a number, the function coerces non-numeric string arguments (e.g. 'a string') and string arguments that are not constants to the type NUMBER(18,5).

For numeric string arguments that are not constants, if NUMBER(18,5) is not sufficient to represent the numeric value, you should cast the argument to a type that can represent the value.

• Either expression can include a SELECT statement containing set operators, such as UNION, INTERSECT, EXCEPT, and MINUS. When using set operators, make sure that data types are compatible. For details, see the General Usage Notes in the Set Operators topic.

## Examples¶

SELECT a, b, IFNULL(a,b), IFNULL(b,a) FROM i;

--------+--------+-------------+-------------+
a    |   b    | ifnull(a,b) | ifnull(b,a) |
--------+--------+-------------+-------------+
0      | 5      | 0           | 5           |
0      | [NULL] | 0           | 0           |
[NULL] | 5      | 5           | 5           |
[NULL] | [NULL] | [NULL]      | [NULL]      |
--------+--------+-------------+-------------+