开发指南—函数—位函数
简介:
本文介绍了PolarDB-X支持的位函数。 位函数分为两类,一是标量函数,二是聚合函数。<div class="article-inner" id="lark-content"><div class="lake-content-editor-core lake-engine lake-typography-traditional"><h2 style="padding:7px 0px;margin:0px;font-weight:700;font-size:24px;line-height:32px">PolarDB-X支持的标量位函数</h2><div><table style="width
PolarDB-X支持的标量位函数
| 函数名 |
描述 |
| | |
按位或 |
| ^ |
按位异或 |
| & |
按位与 |
| BIT_COUNT() |
统计二进制数中1的个数 |
PolarDB-X支持的聚合位函数
| 函数名 |
描述 |
| BIT_OR() |
按位或 |
| BIT_XOR() |
按位异或 |
| BIT_AND() |
按位与 |
示例
BIT_COUNT()返回参数对应的二进制数中1的个数;若参数为NULL,则返回NULL。
mysql> SELECT BIT_COUNT(29), BIT_COUNT(b'101010');
+--------------+----------------------+
| BIT_COUNT(29) | BIT_COUNT(b'101010') |
+--------------+----------------------+
| 4 | 3 |
+--------------+----------------------+
1 row in set (0.00 sec)
mysql> SELECT BIT_COUNT(NULL);
+-----------------+
| BIT_COUNT(NULL) |
+-----------------+
| NULL |
+-----------------+
1 row in set (0.00 sec)
mysql> SELECT 3 & 2;
+-------+
| 3 & 2 |
+-------+
| 2 |
+-------+
1 row in set (0.01 sec)