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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-01 09:56:52
Original
1881 people have browsed it

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

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

1. 在GBK 编码下:

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

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

 

2.在UTF-8 编码下

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

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

 

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

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

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

Related labels:
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
Latest Issues
MySQL stops process
From 1970-01-01 08:00:00
0
0
0
Error when installing mysql on linux
From 1970-01-01 08:00:00
0
0
0
phpstudy cannot start mysql?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template