GBase 8a中一個字元佔用位元組數說明

wjc_gbase發表於2022-01-07

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部落格 ” ,連結:http://blog.itpub.net/69986691/viewspace-2851085/,如需轉載,請註明出處,否則將追究法律責任。

相關文章