Syntax
IFNULL(expr1, expr2)
Purpose
If expr1 is not NULL, the IFNULL() function returns expr1; otherwise, it returns expr2. The return value of IFNULL() is a number or a string, depending on the context in which it is used.
The default return type of IFNULL() is determined as follows:
Expression |
Return type |
|---|---|
expr1 or expr2 returns a string. |
String |
expr1 or expr2 returns a floating-point value. |
Float |
expr1 or expr2 returns an integer. |
Integer |
If both expr1 and expr2 are strings and either of them is case-sensitive, the 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
