Mega Code Archive

 
Categories / MySQL / Data Type
 

Passing a NULL value to a function results in a NULL return value

mysql> mysql> SELECT CONCAT('a','b'), CONCAT('a',NULL,'b'); +-----------------+----------------------+ | CONCAT('a','b') | CONCAT('a',NULL,'b') | +-----------------+----------------------+ | ab              | NULL                 | +-----------------+----------------------+ 1 row in set (0.00 sec) mysql> But not all functions behave that way. CONCAT_WS() (concatenate with separator) simply ignores NULL arguments entirely: mysql> mysql> SELECT CONCAT_WS('/','a','b'), CONCAT_WS('/','a',NULL,'b'); +------------------------+-----------------------------+ | CONCAT_WS('/','a','b') | CONCAT_WS('/','a',NULL,'b') | +------------------------+-----------------------------+ | a/b                    | a/b                         | +------------------------+-----------------------------+ 1 row in set (0.00 sec) mysql>