Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
646 views
in Technique[技术] by (71.8m points)

sql - How to convert from varbinary to char/varchar in mysql

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Late answer...

You can use CAST or CONVERT thus

CAST(foo AS CHAR(100))
CONVERT(foo, CHAR(100))

Supported types (5.5) are:

BINARY[(N)]
CHAR[(N)]
DATE
DATETIME
DECIMAL[(M[,D])]
SIGNED [INTEGER]
TIME
UNSIGNED [INTEGER]

You can not cast to varchar directly.
There is an open MySQL bug from 2008 which no-one seems to care about and is damn annoying


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...