Storing binary string in MySQL

筅森魡賤 提交于 2019-12-05 06:45:00

To check if a bit is set your query needs to be:

SELECT * FROM _table_ x WHERE x.options & (1 << 4) != 0

And to check if it's not set:

SELECT * FROM _table_ x WHERE x.options & (1 << 4) = 0

Update: Here's how to set an individual bit:

UPDATE table SET options = options | (1 << 4)

To clear an individual bit:

UPDATE table SET options = options &~ (1 << 4)

You can also set them all at once with a binary string:

UPDATE table SET options = b'00010010'

Would the SET field type be of any use here?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!