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.
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!