Purpose
This function compares two expressions. If expr1 is equal to expr2, it returns NULL. Otherwise, it returns expr1.
Syntax
NULLIF(expr1, expr2)
Parameters
Parameter |
Description |
|---|---|
| expr1 | The first expression, which can be of any data type. |
| expr2 | The second expression. If expr1 is not a numeric data type, expr2 must be of the same data type as expr1. Otherwise, an error is returned. |
Return type
If both
expr1andexpr2are numeric data types, the database determines the data type with higher precedence, implicitly converts the other expression to this data type, and returns the data type.If
expr1is equal toexpr2orexpr1isNULL, it returnsNULL.If
expr1is not equal toexpr2, it returns the data type ofexpr1.
Examples
Compare 3+4 and 6+1 to see if they are equal.
obclient> SELECT NULLIF(3+4,6+1) FROM DUAL;
+-----------------+
| NULLIF(3+4,6+1) |
+-----------------+
| NULL |
+-----------------+
1 row in set
