Reputation: 1338
I have a bit field in a table and the data in the field looks like '0100' or '1100', etc. It is just a string of 1's and 0's. The type of the field in MySQL is 'BIT'. I need to read the data as a string. So I simply need to say:
select bit_field from mytable
but I need the bit field to come back as a string so I have tried
select CAST(bit as text) from mytable
but that throws an error. Also
select Convert(bit_field as UTF8) from mytable
returns the wrong type of data.
How can I accomplish this so that it returns bit_field as a string of text that looks like "0101" (or whatever is in the field)?
Upvotes: 5
Views: 6263
Reputation: 34294
I would use the export_set() function:
select export_set(bit_field,'1','0','',4) from mytable
Upvotes: 8