Home >Database >Mysql Tutorial >mysql length(获取字符串长度)函数实例分析

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

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

mysql length()函数用于获取字符串的长度,本文章向码农介绍length函数的使用实例:

1.mysql length获取中文字符的长度

<code class="language-sql">select length('码农'); </code>

查询结果有两种情况:

  1. 在GBK 编码下,1个中文字符占2个字节,所以总字节长度4
  2. 在TF-8 编码下,1个中文字符占3个字节,所以总字节长度6

 

2.mysql length获取英文字符的长度

<code>select length('manong'); </code>

1个英文字符占1个字节,所以总字节长度6.

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