The IFNULL Function - If NULL query in SQL statements |
|
| IFNULL | Syntax: | IFNULL(Expression, Value) | Return value: | Depending on the data types used | Synonyms: | NVL | Function type: | NULL function | |
| | The IFNULL() function returns "Value" if the value of "Expression" is NULL.
If "Expression" is not NULL, IFNULL() returns the "Expression".
The return type corresponds to the data type of "Expression" or "Value", depending on the result of the function. | SQL Examples for the IFNULL function |
|
SELECT ifnull(null, 'Value');
SELECT ifnull('ok', 'Value');
SELECT ifnull(nullif('ok', 'notok'), 'value');
SELECT ifnull(nullif('ok', 'ok'), 'value');
SELECT ifnull(nullif('ok', 'ok'), null);
|
|
ifnull(null, 'Value') |
varchar(5) BINARY |
Value |
|
|
ifnull('ok', 'Value') |
varchar(5) BINARY |
ok |
|
|
ifnull(nullif('ok', 'notok'), 'value') |
varchar(5) BINARY |
ok |
|
|
ifnull(nullif('ok', 'ok'), 'value') |
varchar(5) BINARY |
value |
|
|
ifnull(nullif('ok', 'ok'), null) |
varchar(2) BINARY |
NULL |
|
|
| The examples were created with the MyWAY SQL manager: | How to use the IFNULL() function in MySQL and MariaDB databases | With the IFNULL() function in MySQL and MariaDB databases, NULL values in queries or expressions are processed by providing a default or alternate value as a replacement value when the value of a column or expression evaluates to NULL. The function can be used to avoid NULL values interfering with calculations, comparisons, or the display of results. | | Further MySQL und MariaDB SQL NULL functions | |
| | More information about the IFNULL SQL function: and and |
|
|
|
|