连接字符串时,如果添加NULL值,CONCAT_WS()函数的输出结果会是什么?
实际上,只有当CONCAT_WS()函数的第一个参数(即分隔符)为NULL时,该函数才会返回NULL。示例如下:
mysql> Select CONCAT_ws(NULL,'Tutorial','Point','.com'); +-------------------------------------------+ | CONCAT_ws(NULL,'Tutorial','Point','.com') | +-------------------------------------------+ | NULL | +-------------------------------------------+ 1 row in set (0.00 sec)
否则,如果在CONCAT_WS()函数中连接字符串时在任何其他位置放置NULL值,MySQL CONCAT_WS()函数会忽略该NULL值。以下示例将对此进行说明:
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)
广告