MySQL IFNULL() Function
The IFNULL() function is used to determine whether the first expression is NULL. If it is NULL, it returns the value of the second parameter; if it is not NULL, it returns the value of the first parameter.
The syntax format of the IFNULL() function is:
IFNULL(expression, alt_value)
If the expression of the first parameter is NULL, the alternative value of the second parameter is returned.
Parameter description:
| Parameter | Description |
|---|---|
| expression | Required, the value to be tested |
| alt_value | Required, the value returned when the expression is NULL |
Example
The first parameter is NULL:
SELECT IFNULL(NULL, "EXAMPLE");
The output result of the above example is:
EXAMPLE
The first parameter is not NULL:
SELECT IFNULL("Hello", "EXAMPLE");
The output result of the above example is:
HelloOther extensions
MySQL Functions