Bit values start with the prefix b /B or 0b /0B and are composed of binary digits 0 and 1. The following are valid bit values:
b'11'
B'11'
0b11
0B11
The following are invalid bit values:
b'3' (3 is not a binary digit)
By default, bit values are binary strings:
obclient> SELECT b'1000001', CHARSET(b'1000001');
+------------+---------------------+
| b'1000001' | CHARSET(b'1000001') |
+------------+---------------------+
| A | binary |
+------------+---------------------+
1 row in set
obclient> SELECT 0b1100001, CHARSET(0b1100001);
+-----------+--------------------+
| 0b1100001 | CHARSET(0b1100001) |
+-----------+--------------------+
| a | binary |
+-----------+--------------------+
1 row in set
OceanBase Database treats bit values as integers. To ensure that bit values are not treated as numbers, you can add 0 or use CAST(... AS UNSIGNED). By default, bit values assigned to user-defined variables are binary strings.
obclient> SET @v1 = b'1100001';
Query OK, 0 rows affected
obclient> SET @v2 = b'1100001'+0;
Query OK, 0 rows affected
obclient> SET @v3 = CAST(b'1100001' AS UNSIGNED);
Query OK, 0 rows affected
obclient> SELECT @v1, @v2, @v3;
+------+------+------+
| @v1 | @v2 | @v3 |
+------+------+------+
| a | 97 | 97 |
+------+------+------+
1 row in set