samuelbrody1249
samuelbrody1249

Reputation: 4767

How to insert a binary value into mysql

Is there a flag to indicate that data is of binary type, or does that need to be converted to another type. For example, is there a way to do:

INSERT INTO mytable (number) VALUES (0000 0010)

Instead of:

INSERT INTO mytable (number) VALUES (2)

I know the above is a trivial example but basically I'm wondering if you can type a binary/hex value directly into a query.

Upvotes: 1

Views: 107

Answers (1)

Barmar
Barmar

Reputation: 780655

You can use a bit-value literal

INSERT INTO mytable (number) VALUES (b'00000010');
or
INSERT INTO mytable (number) VALUES (0b00000010)

Upvotes: 4

Related Questions