5

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)?

1 Answer 1

8

I would use the export_set() function:

select export_set(bit_field,'1','0','',4) from mytable
Sign up to request clarification or add additional context in comments.

1 Comment

Excellent. Just what I needed. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.