Home > Database > Mysql Tutorial > body text

mysql字符串长度函数char_length、length、bit_length区别

WBOY
Release: 2016-06-07 16:42:05
Original
1338 people have browsed it

mysql GBK 编码下 无论中文字符还是西文字符,都是等同对待,所以总字符数2 select char_length(字符); 1个中文字符占2个字节,所以总字节长度4 select length(字符); 1个英文字符占1个字节,所以总字节长度5 select length(china); 1个中文字符占2个字节,1

mysql

— GBK 编码下—–

–无论中文字符还是西文字符,都是等同对待,所以总字符数2
select char_length(‘字符’);

– 1个中文字符占2个字节,所以总字节长度4
select length(‘字符’);

– 1个英文字符占1个字节,所以总字节长度5
select length(‘china’);

– 1个中文字符占2个字节,1个字节占8位,所以总bit比特长度32
select bit_length(‘字符’);

—- UTF-8 编码下—–

–无论中文字符还是西文字符,都是等同对待,所以总字符数2
select char_length(‘字符’);

– 1个中文字符占3个字节,所以总字节长度6
select length(‘字符’);

– 1个英文字符占1个字节,所以总字节长度5
select length(‘china’);

– 1个中文字符占3个字节,1个字节占8位,所以总bit比特长度48
select bit_length(‘字符’);

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template