Home  >  Article  >  Database  >  What is the difference between CONCAT() and CONCAT_WS() functions?

What is the difference between CONCAT() and CONCAT_WS() functions?

王林
王林forward
2023-08-30 22:57:021013browse

CONCAT() 和 CONCAT_WS() 函数有什么区别?

CONCAT() and CONCAT_WS() functions are both used to concatenate two or more strings, but the basic difference between them is that the CONCAT_WS() function can concatenate between strings delimiters are concatenated together, but there is no concept of delimiters in the CONCAT() function. The other important difference between them is that the CONCAT() function returns NULL if any argument is NULL, whereas the CONCAT_WS() function returns NULL if the delimiter is NULL.

Example

The following example demonstrates the difference between the CONCAT() and CONCAT_WS() functions -

mysql> Select CONCAT('Ram','is','a','good','student') AS 'Example of CONCAT()';

+---------------------+
| Example of CONCAT() |
+---------------------+
| Ramisagoodstudent   |
+---------------------+

1 row in set (0.00 sec)

mysql> Select CONCAT_WS(' ','Ram','is','a','good','student') AS 'Example of CONCAT_WS()';

+------------------------+
| Example of CONCAT_WS() |
+------------------------+
| Ram is a good student  |
+------------------------+

1 row in set (0.00 sec)

The above is the detailed content of What is the difference between CONCAT() and CONCAT_WS() functions?. 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