連線字串時,如果新增NULL值,CONCAT_WS()函式的輸出結果會是什麼?


實際上,只有當CONCAT_WS()函式的第一個引數(即分隔符)為NULL時,該函式才會返回NULL。示例如下:

mysql> Select CONCAT_ws(NULL,'Tutorial','Point','.com');
+-------------------------------------------+
| CONCAT_ws(NULL,'Tutorial','Point','.com') |
+-------------------------------------------+
| NULL                                      |
+-------------------------------------------+
1 row in set (0.00 sec)

否則,如果在CONCAT_WS()函式中連線字串時在任何其他位置放置NULL值,MySQL CONCAT_WS()函式會忽略該NULL值。以下示例將對此進行說明:

mysql> Select CONCAT_ws('s','Tutorial','Point','.com',NULL);
+-----------------------------------------------+
| CONCAT_ws('s','Tutorial','Point','.com',NULL) |
+-----------------------------------------------+
| TutorialsPoints.com                           |
+-----------------------------------------------+
1 row in set (0.00 sec)

mysql> Select CONCAT_ws('s','Tutorial',NULL,'Point','.com');
+-----------------------------------------------+
| CONCAT_ws('s','Tutorial',NULL,'Point','.com') |
+-----------------------------------------------+
| TutorialsPoints.com                           |
+-----------------------------------------------+
1 row in set (0.00 sec)

更新於:2020年6月22日

85次瀏覽

啟動您的職業生涯

完成課程獲得認證

開始學習
廣告