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
The VARBINARY type is similar to the VARCHAR type, but stores binary byte strings rather than non-binary character strings. M represents the maximum column length in bytes. It contains no character set, and comparison and sorting are based on the numeric value of the bytes.
The MySQL CAST() function is used for converting a value from one datatype to another specific datatype. The CAST() function accepts two parameters which are the value to be converted and the datatype to which the value needs to be converted.
Implicit conversion from data type varchar to varbinary is not allowed. Use the CONVERT function to run this query. The problem is that the query plan hashes are already in binary format, however stored as VARCHAR in the XML Query Plan e.g.
VarBinary is a variable width data type. The syntax for declaring Binary variable is varbinary(n) , where n defines the maximum size in bytes. The varbinary data type uses actual length of the data entered + 2 bytes as the storage.
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
The MySQL syntax that worked for me in a similar scenario to this is:
select cast(binaryColumn as CHAR) from table_name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With