MySQL returning an empty field: CONCAT(nonEmpty1,empty2,nonEmpty3) = NULL

前端 未结 6 1335
攒了一身酷
攒了一身酷 2021-02-19 10:27

I have PHP 5 code accessing a MyISAM table on MySQL 5 server. The query looks like this:

SELECT CONCAT(fName1,\' \',mName2,\' \',lName3) AS userName 
    FROM us         


        
6条回答
  •  轮回少年
    2021-02-19 11:23

    From google: http://bugs.mysql.com/bug.php?id=480

    [23 May 2003 4:32] Alexander Keremidarski

    Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.mysql.com/documentation/ and the instructions on how to report a bug at http://bugs.mysql.com/how-to-report.php

    This is doccumented behaviour of CONCAT() function.

    From Manual chapter 6.3.2 String Functions

    CONCAT(str1,str2,...) Returns the string that results from concatenating the arguments. Returns NULL if any argument is NULL

    Use CONCAT_WS() instead or wrap NULLable paremeters with IFNULL() function.

    Documentation and usage for CONCAT_WS: http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat-ws

提交回复
热议问题