从位字段中按索引获取一位,mysql
有没有办法从 mysql 中的位字段获取一位(或布尔值)?
我想出的唯一解决方案是使用以下内容: 我想要位置三的位值。
SELECT bit_count(bin(column) & b'100') AS bitValue FROM table;
该查询的输出要么是 1,要么是 0。但它看起来不太好。 有没有更好的方法来获取位字段中特定位置的位值? 读取位值将在我的 Web 应用程序中大量完成,您认为获取我上面使用的值的方式会对性能产生问题吗?我的意思是同时使用 bit_count 和 BIN() 以及“and”运算符..
我正在寻找类似的内容:
SELECT column(3) FROM table;
感谢您的阅读!
马蒂亚斯。
Is there a way to get one bit (or bool) from a bit field in mysql?
The only solution i've came up with is to use the following:
i want the bit value at position three.
SELECT bit_count(bin(column) & b'100') AS bitValue FROM table;
The output from this query is either a one or a zero. But it does not look so nice.
Is there a better way to get the bit value at a specific position in a bit field?
Reading the bit values would be done heavily at my web application, do you think that the way of getting the value that i used above would be a problem for the performance?? i mean with both a bit_count and a BIN() and "and" operator..
I am looking for something like:
SELECT column(3) FROM table;
Thanks for reading!
Mattias.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您担心读取性能并且您感兴趣的位是固定的,请尝试提取该位并将其插入布尔列中。如果您尝试提取的位是动态的,我认为您的解决方案是最佳的。
If you are worried about read performance and the bit you are interested in is fixed, try to extract the bit and insert it into a boolean column. If the bit you are trying to extract is dynamic, I think your solutions is optimal.