首页 >数据库 >mysql教程 >MySQL ISNULL() 函数和 IS NULL 运算符有什么区别?

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

WBOY
WBOY转载
2023-08-30 16:13:02983浏览

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

显然,ISNULL()函数和IS NULL运算符没有任何区别,并且共享一些共同的行为。我们唯一能看到的区别是它们的语法。ISNULL()函数将表达式作为其参数,而IS NULL比较运算符将表达式放在其左侧。否则,如果表达式为NULL,则两者都返回1,如果表达式不为NULL,则返回0。以下示例将演示上述概念−

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)

以上是MySQL ISNULL() 函数和 IS NULL 运算符有什么区别?的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:tutorialspoint.com。如有侵权,请联系admin@php.cn删除