IFNULL

2023-07-28 02:53:17  Updated

Syntax

IFNULL(expr1, expr2)

Purpose

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.

Expressions Return values
The return value of expr1 or expr2 is a string. Strings.
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

Contact Us