IFNULL

2023-10-24 09:23:03  Updated

Syntax

IFNULL(expr1, expr2)

Notes

Assume that expr1 is not NULL. The return value of IFNULL() is expr1. Otherwise, its return value is expr2. The return value of IFNULL() is a numeric value or a string, depending on the context.

The default return value type of IFNULL() is determined based on the following rules.

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 value. 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 (0.01 sec)

Contact Us