使用CONCAT和NULL值

时间:2022-01-11 07:53:00

Why is my entire string blank when I output data using php doing:

当我使用php输出数据时,为什么我的整个字符串都是空白的:

select concat(name, desc) as output from reports where type=2

And the data in the table is:

表中的数据是:

Name Desc
a    desc a
b    null
c    null

Output using php:

使用php输出:

a desc a
blank space
blank space

If I didn't use concat, the output is as usual. I'm using concat so I can output everything in one variable when using php.

如果我没有使用concat,输出就像往常一样。我正在使用concat所以我可以在使用php时输出一个变量中的所有内容。

1 个解决方案

#1


1  

you can use CONCAT_WS()

你可以使用CONCAT_WS()

concat_ws('', name, `desc`)

or with COALESCE()

或与COALESCE()

concat(name, COALESCE(`desc`,''))

#1


1  

you can use CONCAT_WS()

你可以使用CONCAT_WS()

concat_ws('', name, `desc`)

or with COALESCE()

或与COALESCE()

concat(name, COALESCE(`desc`,''))