在链接字符串时,如果我将添加NULL值,那么CONCAT_WS()函数的输出将是什么?

实际上,当且仅当它的第一个参数(即分隔符)为NULL时,CONCAT_WS()函数才返回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) |
+-----------------------------------------------+
| nhooos.com                           |
+-----------------------------------------------+
1 row in set (0.00 sec)

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