【问题标题】:mysql string concatenation returns 0mysql字符串连接返回0
【发布时间】:2011-09-05 07:48:07
【问题描述】:
我试图在选择查询中连接 3 列以显示在结果的一列中。该列称为 DelPostalName,由于某种原因,当我运行选择查询时总是显示“0”。就像它试图将字符串相加但没有实际数字要添加一样。我一直在谷歌搜索字符串连接,这似乎是正确的语法。有任何想法吗?
isc_orders.ordShipFirstName + ' ' + isc_orders.ordshiplastname + isc_orders.ordshipcompany 作为 DelPostalName,
【问题讨论】:
标签:
mysql
sql
string
concatenation
【解决方案1】:
结果显示为 0,因为您正试图通过算术将字符串彼此相加。
在 MySQL 中连接字符串的正确方法是使用 CONCAT(str1, str2, str3) 函数。
Here 是函数的手册。
PS:如果您想与分隔符连接,请使用 CONCAT_WS() - 也在同一手册中
【解决方案2】:
你应该像这样使用CONCAT(正如一些人提到的):
CONCAT(isc_orders.ordShipFirstName,' ',
isc_orders.ordshiplastname,' ',
isc_orders.ordshipcompany)
AS DelPostalName