Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2023-09-07 10:41:02
forward
1060 people have browsed it

在链接字符串时,如果我添加 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)
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template