实际上,当且仅当 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)
否则,如果我们在链接字符串时将 NULL 放置在 CONCAT_WS() 函数中的任何其他位置,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)