How to convert from varbinary to char/varchar in mysql

后端 未结 3 1670
一生所求
一生所求 2020-11-30 10:03

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

相关标签:
3条回答
  • 2020-11-30 10:25

    You can use cast operation:

    select cast(column_name as char)
      from table_name
    
    0 讨论(0)
  • 2020-11-30 10:26

    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

    0 讨论(0)
  • 2020-11-30 10:29

    The MySQL syntax that worked for me in a similar scenario to this is:

    select cast(binaryColumn as CHAR) from table_name
    
    0 讨论(0)
提交回复
热议问题