Home > Database > Mysql Tutorial > mysql char_length length bit_length区别实例分析

mysql char_length length bit_length区别实例分析

WBOY
Release: 2016-06-01 09:56:50
Original
1026 people have browsed it

分两种情况:

1. GBK 编码下

--无论中文字符还是西文字符,都是等同对待,所以总字符数2

<code class="language-sql">select char_length('中国');</code>
Copy after login
Copy after login

 

-- 1个中文字符占2个字节,所以总字节长度4

<code class="language-sql">select length('中国'); </code>
Copy after login
Copy after login

 

-- 1个英文字符占1个字节,所以总字节长度5

<code class="language-sql">select length('china');</code>
Copy after login

 

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

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

 

 

2. UTF-8 编码下

--无论中文字符还是西文字符,都是等同对待,所以总字符数2

<code class="language-sql">select char_length('中国');</code>
Copy after login
Copy after login

 

-- 1个中文字符占3个字节,所以总字节长度6

<code class="language-sql">select length('中国'); </code>
Copy after login
Copy after login

 

-- 1个英文字符占1个字节,所以总字节长度5

<code class="language-sql">select length('china'); </code>
Copy after login

 

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

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

 

相关阅读:

mysql length(获取字符串长度)函数实例分析

mysql char_length()获取字符串长度

mysql 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