drop table if exists tb;create table tb(c char(10), vc varchar(10));
insert into tb select 'ab','vc';
select tb.*, length(tb.c) c_len, length(vc) vc_len from tb;
-- result
-- ab, vc, 2, 2
为什么 ab字段的长度不是10呢,而是2呢,char不是定长的吗应该占据10个字符串的位置吗?
insert into tb select 'ab','vc';
select tb.*, length(tb.c) c_len, length(vc) vc_len from tb;
-- result
-- ab, vc, 2, 2
为什么 ab字段的长度不是10呢,而是2呢,char不是定长的吗应该占据10个字符串的位置吗?
看英文资料的时候,没有注意到这句话:
The CHAR and VARCHAR types are similar, but differ in the way they are stored and retrieved. They also differ in maximum length and in whether trailing spaces are retained.