Home >Database >Mysql Tutorial >While concatenating strings, if I add NULL values, what is the output of CONCAT_WS() function?

While concatenating strings, if I add NULL values, what is the output of CONCAT_WS() function?

WBOY
WBOYforward
2023-09-07 10:41:021095browse

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

In fact, the CONCAT_WS() function returns NULL if and only if its first parameter (i.e., the delimiter) is NULL. An example is as follows -

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

Otherwise, MySQL CONCAT_WS() function will ignore NULL if we place NULL anywhere else in CONCAT_WS() function while concatenating strings. The following example will demonstrate it -

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)

The above is the detailed content of While concatenating strings, if I add NULL values, what is the output of CONCAT_WS() function?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete