mysql string concatenation returns 0

∥☆過路亽.° 提交于 2019-12-09 14:36:32

问题


im trying to concatenate 3 columns in a select query to show in one column in the results. the column is called DelPostalName and for some reason always shows a '0' when i run the select query. like its trying to add up the strings but theres not actual numbers to add. ive been googling string concatenation and this seems to be the correct syntax. any ideas?

isc_orders.ordShipFirstName + ' ' + isc_orders.ordshiplastname + isc_orders.ordshipcompany as DelPostalName,

回答1:


The result appears as zero since you are trying to arithmetically add the strings to each other.

The correct method for concatenating strings in MySQL is using the CONCAT(str1, str2, str3) function.

Here is the manual for the function.

PS: if you want to concate with a seperator use CONCAT_WS() - also in the same manual




回答2:


You should use CONCAT (as a few people have mentioned) like this:

CONCAT(isc_orders.ordShipFirstName,' ',
isc_orders.ordshiplastname,' ',
isc_orders.ordshipcompany)
AS DelPostalName



回答3:


Try using concat to concatenate columns/strings.




回答4:


I think you should use concat for concatenation, not + :)



来源:https://stackoverflow.com/questions/6185192/mysql-string-concatenation-returns-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!