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!