GBase 8a支持GBK,UTF8,utf8mb4等字符集,所以一个字符,根据字符集不同,字符不同,占用1-4个字节。
目录导航
普通字符占用1个字节
gbase> create table c1(name varchar(100));
Query OK, 0 rows affected (Elapsed: 00:00:00.11)
gbase> insert into c1 values('abcd');
Query OK, 1 row affected (Elapsed: 00:00:00.08)
gbase> select name,length(name) from c1;
+------+--------------+
| name | length(name) |
+------+--------------+
| abcd | 4 |
+------+--------------+
1 row in set (Elapsed: 00:00:00.01)
GBK字符集汉字占用2个字节
gbase> create table c2(name varchar(100)) charset=GBK;
Query OK, 0 rows affected (Elapsed: 00:00:00.10)
gbase> set names GBK;
Query OK, 0 rows affected (Elapsed: 00:00:00.00)
gbase> insert into c2 values('中国');
Query OK, 1 row affected (Elapsed: 00:00:00.07)
gbase> select * from c2;
+--------+
| name |
+--------+
| 中国 |
+--------+
1 row in set (Elapsed: 00:00:00.01)
gbase> select name,length(name) from c2;
+--------+--------------+
| name | length(name) |
+--------+--------------+
| 中国 | 4 |
+--------+--------------+
1 row in set (Elapsed: 00:00:00.00)
UTF8字符集普通汉字占用3个字节
gbase> set names UTF8;
Query OK, 0 rows affected (Elapsed: 00:00:00.00)
gbase> insert into c1 values('中国');
Query OK, 1 row affected (Elapsed: 00:00:00.08)
gbase> select name,length(name) from c1;
+--------+--------------+
| name | length(name) |
+--------+--------------+
| abcd | 4 |
| 中国 | 6 |
+--------+--------------+
2 rows in set (Elapsed: 00:00:00.01)
生僻汉字和Emoji占用4个字节
gbase> create table c3(name varchar(100)) charset=UTF8MB4;
Query OK, 0 rows affected (Elapsed: 00:00:00.11)
gbase> set names utf8mb4;
Query OK, 0 rows affected (Elapsed: 00:00:00.00)
gbase> insert into c3 values('😃');
Query OK, 1 row affected (Elapsed: 00:00:00.08)
gbase> select name,length(name) from c3;
+------+--------------+
| name | length(name) |
+------+--------------+
| 😃 | 4 |
+------+--------------+
1 row in set (Elapsed: 00:00:00.00)