[英]compare a char-field with a bitmask
I'm trying to select rows by a charfield with the length of 9. It is in collation utf8_gen. 我正在尝试通过长度为9的charfield选择行。它在排序规则utf8_gen中。
My where-condition is that the first n bits of a stored value have to match my given bitmask. 我的条件是存储值的前n位必须与给定的位掩码匹配。
One example: 一个例子:
data:
id | val | bitmask (not actually stored in the db)
----+-----+-----------------------------------------
1 | AB | 0100000101 000010
2 | Ab | 0100000101 100010
bitmask for where-clause:
0100000101 0
expected selected rows:
1 | AB
Best I could come up with. 我能想出的最好的。 It's pretty ugly.
这很丑。 No guarantee how fast or well it works.
无法保证其运行速度或效果。
SELECT HEX(b'0100000101'<< BIT_LENGTH(myCol) - 10) & HEX(myCol) = HEX(b'0100000101'<< BIT_LENGTH(myCol) - 10);
myCol is the col. myCol是上校。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.