Home  >  Article  >  Database  >  What is the use of the MySQL CONCAT_WS() function?

What is the use of the MySQL CONCAT_WS() function?

PHPz
PHPzforward
2023-08-26 11:09:181410browse

MySQL CONCAT_WS() 函数有什么用?

Basically, MySQL CONCAT_WS() function is used to concatenate two or more strings along with the delimiter. The keyword WS in CONCAT_WS() here represents WITH SEPARATOR. We can pronounce the CONCAT_WS() function as a concatenation function with delimiters.

grammar

CONCAT_WS(Separator, String1,String2,…,StringN)

Here, the parameters of the CONCAT_WS function are the delimiter and the string that needs to be concatenated with the delimiter into a single string. Delimiters other than numeric values ​​must be enclosed in quotes.

Example

mysql> SELECT CONCAT_WS(' ','New', 'Delhi');

+-------------------------------+
| CONCAT_WS(' ','New', 'Delhi') |
+-------------------------------+
| New Delhi                     |
+-------------------------------+

1 row in set (0.00 sec)

In the above example, we can see that the string " " (i.e. space) is used as a separator and inserted between the two strings (New and Delhi) that need to be concatenated.

mysql> SELECT CONCAT_WS(' is our ','Delhi','Capital');

+-----------------------------------------+
| CONCAT_WS(' is our ','Delhi','Capital') |
+-----------------------------------------+
| Delhi is our Capital                    |
+-----------------------------------------+

1 row in set (0.00 sec)

In the above example, we can see that the string "is our" is inserted as a separator between the two strings Delhi and Capital that need to be concatenated.

The above is the detailed content of What is the use of the MySQL 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