Skip to content

IFNULL

Grammar Description

If expr1 is not NULL, then IFNULL() returns expr1; otherwise expr2 is returned.

Grammar Structure

> IFNULL(expr1,expr2)

Example

mysql> SELECT IFNULL(NULL,10);
+------------------------+
| ifnull(null, 10) |
+------------------------+
| 10 |
+------------------------+
1 row in set (0.01 sec)
mysql> SELECT CAST(IFNULL(NULL, NULL) AS DECIMAL);
+---------------------------------------------------+
| cast(ifnull(null, null) as decimal(38)) |
+---------------------------------------------------+
| NULL |
+---------------------------------------------------+
1 row in set (0.01 sec)