What is the use of MySQL IFNULL() control flow function?

MySQLMySQLi Database

MySQL IFNULL() control flow function will return the first argument if it is not NULL otherwise it returns the second argument.

Syntax

IFNULL(expression1, expression2)

Here if expression1 is not NULL then IFNULL() will return expression1 otherwise expression2. It will return NULL if both of the arguments are NULL. Following example will exhibit this −

mysql> Select IFNULL(NULL,'Ram');
+--------------------+
| IFNULL(NULL,'Ram') |
+--------------------+
| Ram                |
+--------------------+
1 row in set (0.00 sec)

mysql> Select IFNULL('Shyam','Ram');
+-----------------------+
| IFNULL('Shyam','Ram') |
+-----------------------+
| Shyam                 |
+-----------------------+
1 row in set (0.00 sec)

mysql> Select IFNULL(NULL,NULL);
+-------------------+
| IFNULL(NULL,NULL) |
+-------------------+
| NULL              |
+-------------------+
1 row in set (0.00 sec)
raja
Published on 21-Feb-2018 10:49:24
Advertisements