Home  >  Article  >  Database  >  What is the use of the MySQL IFNULL() control flow function?

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

王林
王林forward
2023-09-11 17:25:02515browse

MySQL IFNULL()控制流函数有什么用?

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

Syntax

IFNULL(expression1, expression2)

Here if expression 1 is not NULL, IFNULL() will return expression 1, otherwise it will return expression 2. If both parameters are NULL, it returns NULL. The following example will demonstrate 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)

The above is the detailed content of What is the use of the MySQL IFNULL() control flow function?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete