Home  >  Article  >  Database  >  What is the difference between the MySQL ISNULL() function and the IS NULL operator?

What is the difference between the MySQL ISNULL() function and the IS NULL operator?

WBOY
WBOYforward
2023-08-30 16:13:02934browse

MySQL ISNULL() 函数和 IS NULL 运算符有什么区别?

Obviously, there is no difference between the ISNULL() function and the IS NULL operator, and share some common behavior. The only difference we can see is their syntax. The ISNULL() function takes an expression as its argument, while the IS NULL comparison operator puts the expression on its left. Otherwise, both return 1 if the expression is NULL, or 0 if the expression is not NULL. The following example will demonstrate the above concept −

mysql> Select 1 IS NULL;
+-----------+
| 1 IS NULL |
+-----------+
| 0         |
+-----------+
1 row in set (0.00 sec)

mysql> Select ISNULL(1);
+-----------+
| ISNULL(1) |
+-----------+
| 0         |
+-----------+
1 row in set (0.00 sec)

mysql> Select ISNULL(1/0);
+-------------+
| ISNULL(1/0) |
+-------------+
| 1           |
+-------------+
1 row in set (0.00 sec)

mysql> Select 1/0 IS NULL;
+-------------+
| 1/0 IS NULL |
+-------------+
| 1           |
+-------------+
1 row in set (0.00 sec)

mysql> Select * from Employee WHERE Salary IS NULL;
+----+-------+--------+
| ID | Name  | Salary |
+----+-------+--------+
| 7  | Aryan | NULL   |
| 8  | Vinay | NULL   |
+----+-------+--------+
2 rows in set (0.00 sec)

mysql> Select * from Employee WHERE ISNULL(Salary);
+----+-------+--------+
| ID | Name | Salary |
+----+-------+--------+
| 7  | Aryan | NULL   |
| 8  | Vinay | NULL   |
+----+-------+--------+
2 rows in set (0.00 sec)

The above is the detailed content of What is the difference between the MySQL ISNULL() function and the IS NULL operator?. 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