Home > Database > Mysql Tutorial > How to use the LENGTH() function in MySQL

How to use the LENGTH() function in MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2023-05-26 21:40:41
forward
3667 people have browsed it

LENGTH()

LENGTH(str) and OCTET_LENGTH(str) functions are used to return the byte length of a string, for example:

SELECT LENGTH('MySQL字符串函数') AS len1, OCTET_LENGTH('MySQL字符串函数') AS len2;
len1|len2|
----+----+
  20|  20|
Copy after login

In utf8mb4 encoding, one Chinese character occupies 3 bytes.

In addition, the CHAR_LENGTH(str) and CHARACTER_LENGTH(str) functions are used to return the character length of the string, which is the number of characters. For example:

SELECT CHAR_LENGTH('MySQL字符串函数') AS len1, CHARACTER_LENGTH('MySQL字符串函数') AS len2;
len1|len2|
----+----+
  10|  10|
Copy after login

BIT_LENGTH(str)The function is used to return the bit length (number of bits) of a string, for example:

SELECT BIT_LENGTH('MySQL字符串函数') AS len;
len|
---+
160|
Copy after login

A byte contains 8 bits.

The above is the detailed content of How to use the LENGTH() function in MySQL. For more information, please follow other related articles on the PHP Chinese website!

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