A bit value starts with b, B, 0b, or 0B, followed by binary digits of 0 and 1. Examples of valid bit values:
b'11'
B'11'
0b11
0B11
Example of an invalid bit value:
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 (0.00 sec)
obclient> SELECT 0b1100001, CHARSET(0b1100001);
+-----------+--------------------+
0b1100001 CHARSET(0b1100001)
+-----------+--------------------+
a binary
+-----------+--------------------+
1 row in set (0.00 sec)
OceanBase Database treats a bit value as an integer. To ensure that a bit value is not treated as a number, you can add a 0 to the value or call the CAST(... AS UNSIGNED) function. By default, the bit value assigned to a user-defined variable is a binary string.
obclient> SET @v1 = b'1100001';
Query OK, 0 rows affected (0.01 sec)
obclient> SET @v2 = b'1100001'+0;
Query OK, 0 rows affected (0.00 sec)
obclient> SET @v3 = CAST(b'1100001' AS UNSIGNED);
Query OK, 0 rows affected (0.00 sec)
obclient> SELECT @v1, @v2, @v3;
+------+------+------+
@v1 @v2 @v3
+------+------+------+
a 97 97
+------+------+------+
1 row in set (0.00 sec)