MySQL 如何在mysql中从varbinary转换为char/varchar
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1873085/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to convert from varbinary to char/varchar in mysql
提问by Saeros
I have a field which is varbinary. It has already been populated. Now how do i convert varbinary to varchar so that I can use the data in the field for some other purpose. I use a MySQL version 5.10
我有一个 varbinary 字段。它已经被填充了。现在我如何将 varbinary 转换为 varchar 以便我可以将字段中的数据用于其他目的。我使用 MySQL 5.10 版
回答by gbn
Late answer...
迟到的回答...
You can use CAST or CONVERT thus
您可以因此使用 CAST 或 CONVERT
CAST(foo AS CHAR(100))
CONVERT(foo, CHAR(100))
BINARY[(N)]
CHAR[(N)]
DATE
DATETIME
DECIMAL[(M[,D])]
SIGNED [INTEGER]
TIME
UNSIGNED [INTEGER]
You can notcast to varchar directly.
There is an open MySQL bug from 2008which no-one seems to care about and is damn annoying
您不能直接转换为 varchar。从 2008 年开始
有一个开放的 MySQL 错误,似乎没有人关心,而且很烦人
回答by yanigisawa
The MySQL syntax that worked for me in a similar scenario to this is:
在与此类似的情况下,对我有用的 MySQL 语法是:
select cast(binaryColumn as CHAR) from table_name
回答by Pablo Santa Cruz
You can use cast operation:
您可以使用强制转换操作:
select cast(column_name as varchar)
from table_name