在连接字符串时,如果添加一个 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)
广告