本文介绍GBase 8a数据库集群字符串函数BIN的语法、用法说明和使用例子。
目录导航
语法
BIN(N)
说明
返回 N 的二进制形式,N 是 BIGINT 类型数值;
如果 N 是一个 NULL,返回值为 NULL。
用例
数字
gbase> select bin(10);
+---------+
| bin(10) |
+---------+
| 1010 |
+---------+
1 row in set (Elapsed: 00:00:00.00)
gbase> select bin('123456');
+-------------------+
| bin('123456') |
+-------------------+
| 11110001001000000 |
+-------------------+
1 row in set (Elapsed: 00:00:00.01)
字符串
如果能直接转为数字,则返回最前面能转化的部分。否则返回0.
gbase> select bin('10');
+-----------+
| bin('10') |
+-----------+
| 1010 |
+-----------+
1 row in set (Elapsed: 00:00:00.00)
gbase> select bin('10BC');
+-------------+
| bin('10BC') |
+-------------+
| 1010 |
+-------------+
1 row in set (Elapsed: 00:00:00.00)
如果不能直接,包括16进制表示形式的字符串,也都是报错返回。必须用cast强制转成int类型才可以。
gbase> select bin(0xabcd);
+-------------+
| bin(0xabcd) |
+-------------+
| 0 |
+-------------+
1 row in set (Elapsed: 00:00:00.00)
gbase> select bin(cast(0xabcd as int));
+--------------------------+
| bin(cast(0xabcd as int)) |
+--------------------------+
| 1010101111001101 |
+--------------------------+
1 row in set (Elapsed: 00:00:00.00)
空值和NULL值
都返回null
gbase> select bin(''),bin(null);
+---------+-----------+
| bin('') | bin(null) |
+---------+-----------+
| NULL | NULL |
+---------+-----------+
1 row in set (Elapsed: 00:00:00.00)