显然,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 运算符有什么区别?的详细内容,更多请关注每日运维网(www.mryunwei.com)其它相关文章!