ITPub博客

首页 > 数据库 > 国内数据库 > GBase 8a中一个字符占用字节数说明

GBase 8a中一个字符占用字节数说明

原创 国内数据库 作者:wjc_gbase 时间:2022-01-07 10:15:51 0 删除 编辑

1、普通字符占用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)


2、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)


3、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)


4、生僻汉字和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)


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69986691/viewspace-2851085/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2020-10-29

  • 博文量
    5
  • 访问量
    3009