Home >Database >Mysql Tutorial >mysql BIT_LENGTH()获取字符串的比特长度

mysql BIT_LENGTH()获取字符串的比特长度

WBOY
WBOYOriginal
2016-06-01 09:56:521788browse

mysql BIT_LENGTH()获取字符串的比特长度。

需要注意的是,在获取中文字符串比特长度时,不同编码获取的比特长度不一样,请看下面两个实例:

1. 在GBK 编码下:

<code class="language-sql">select bit_length('中国');  
结果:32</code>

1个中文字符占2个字节,1个字节占8位,所以总bit比特长度32

 

2.在UTF-8 编码下

<code class="language-sql">select bit_length('中国'); 
结果:48</code>

1个中文字符占3个字节,1个字节占8位,所以总bit比特长度48 

 

下面看一下非中文字符串实例:

<code class="language-sql">SELECT BIT_LENGTH(  'manong' )
结果:48</code>

1个英文字符占1个字节,1个字节占8位,所以结果为48.

Statement:
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