暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

gbase 8a中字符占用字节大小

墨天轮DB 2022-02-07
833

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)
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论