更新时间:2024-12-13 GMT+08:00
Bitwise函数
- bit_count(x, bits) → bigint
SELECT bit_count(9, 64); -- 2 SELECT bit_count(9, 8); -- 2 SELECT bit_count(-7, 64); -- 62 SELECT bit_count(-7, 8); -- 6
- bitwise_and(x, y) → bigint
select bitwise_and(8, 7); -- 0
- bitwise_not(x) → bigint
select bitwise_not(8);-- -9
- bitwise_or(x, y) → bigint
select bitwise_or(8,7);-- 15
- bitwise_xor(x, y) → bigint
SELECT bitwise_xor(19,25); -- 10
- bitwise_left_shift(value, shift) → [same as value]
描述:返回value左移shift位后的值。
SELECT bitwise_left_shift(1, 2); -- 4 SELECT bitwise_left_shift(5, 2); -- 20 SELECT bitwise_left_shift(0, 1); -- 0 SELECT bitwise_left_shift(20, 0); -- 20
- bitwise_right_shift(value, shift) → [same as value]
SELECT bitwise_right_shift(8, 3); -- 1 SELECT bitwise_right_shift(9, 1); -- 4 SELECT bitwise_right_shift(20, 0); -- 20 SELECT bitwise_right_shift(0, 1); -- 0 -- 右移超过64位,返回0 SELECT bitwise_right_shift( 12, 64); -- 0
- bitwise_right_shift_arithmetic(value, shift) → [same as value]
描述:返回value的算术右移值,当shift小于64位时,返回结果与bitwise_right_shift一样,当移动位数达到或者超过64位时,value是正数时返回0,负数时返回-1:
SELECT bitwise_right_shift_arithmetic( 12, 64); -- 0 SELECT bitwise_right_shift_arithmetic(-45, 64); -- -1
父主题: SQL函数和操作符