首頁 >資料庫 >mysql教程 >MySQL ISNULL() 函數和 IS NULL 運算子有什麼不同?

MySQL ISNULL() 函數和 IS NULL 運算子有什麼不同?

WBOY
WBOY轉載
2023-08-30 16:13:02971瀏覽

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刪除