CONCAT() 和 CONCAT_WS() 函式有什麼不同?
CONCAT() 和 CONCAT_WS() 兩個函式均用於合併兩個或更多字串,但兩者之間最基本的區別是 CONCAT_WS() 函式可以在合併字串時新增分隔符,而 CONCAT() 函式並沒有分隔符的概念。另一個重要的區別是,如果 CONCAT() 函式的任何引數為 NULL,那麼它將返回 NULL,而如果 CONCAT_WS() 函式的分隔符為 NULL,那麼它將返回 NULL。
示例
以下示例演示了 CONCAT() 和 CONCAT_WS() 函式的區別 −
mysql> Select CONCAT('Ram','is','a','good','student') AS 'Example of CONCAT()';
+---------------------+
| Example of CONCAT() |
+---------------------+
| Ramisagoodstudent |
+---------------------+
1 row in set (0.00 sec)
mysql> Select CONCAT_WS(' ','Ram','is','a','good','student') AS 'Example of CONCAT_WS()';
+------------------------+
| Example of CONCAT_WS() |
+------------------------+
| Ram is a good student |
+------------------------+
1 row in set (0.00 sec)
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP