Declaration
IFNULL(expr1, expr2)
Description
Assuming expr1 is not NULL, the return value of IFNULL() is expr1; otherwise, it returns expr2. The return type of IFNULL() is numeric or string, depending on the context in which it is used.
The default return value type of IFNULL() is calculated as follows:
Expression |
Return Value |
|---|---|
The return value of expr1 or expr2 is a string. |
string |
The return value of expr1 or expr2 is a floating-point number. |
floating-point |
The return value of expr1 or expr2 is an integer. |
integer |
If both expr1 and expr2 are strings, and either of them is case-sensitive, the return result is case-sensitive.
Examples
obclient> SELECT IFNULL('abc', null), IFNULL(NULL+1, NULL+2), IFNULL(1/0, 0/1);
+---------------------+------------------------+------------------+
| IFNULL('abc', null) | IFNULL(NULL+1, NULL+2) | IFNULL(1/0, 0/1) |
+---------------------+------------------------+------------------+
| abc | NULL | 0.0000 |
+---------------------+------------------------+------------------+
1 row in set