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