MySQL CONCAT(“string”,longtext) results in hex string

强颜欢笑 提交于 2019-11-30 22:58:01

问题


I'm experiencing a weird hex string result when trying to concat a string with a column that should be of LONGTEXT type.

The query goes like this:

SELECT concat("abc",t.LONGTEXT_VALUE,"cde") FROM mytable t

61626354657374696e67636465

The hex string 61626354657374696e67636465 is the correct value, just in hexadecimal form.

A SELECT on the column itself will return the normal string:

SELECT t.LONGTEXT_VALUE FROM mytable t

Testing

回答1:


Have you tried casting? Usually works pretty well for me. Example:

SELECT CONCAT("abc",CAST(t.LONGTEXT_VALUE AS CHAR),"cde") FROM mytable t



回答2:


When you concat a number without a cast it returns as a blob. This is intended functionality of MySQL as far as I can tell since, it was reported in this bug thread and they closed it and confirmed it was returning a Blob.



来源:https://stackoverflow.com/questions/18840557/mysql-concatstring-longtext-results-in-hex-string

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