Mysql String Length function (CHAR_LENGTH)

Source: Internet
Author: User

Length: the length of a calculated field. A Chinese character is counted as three characters. A number or letter is counted as one character.
The return value of CHAR_LENGTH (str) is the length of the str string, measured in characters. A multi-byte character is counted as a single character. For a five-Byte Character Set, LENGTH () returns 10, while CHAR_LENGTH () returns 5.
CHARACTER_LENGTH (str) CHARACTER_LENGTH () is a synonym for CHAR_LENGTH.
BIT_LENGTH (str) returns the binary length.
For example, you can find a list of users whose usernames are less than 6 characters long.
SQL
Copy codeThe Code is as follows:
SELECT * FROM admin where length (username) <6
 
CHAR_LENGTH (str)
The return value is the length of the str string, measured in characters. A multi-byte character is counted as a single character. For a five-Byte Character Set, LENGTH () returns 10, while CHAR_LENGTH () returns 5.
CHARACTER_LENGTH (str)
CHARACTER_LENGTH () is a synonym for CHAR_LENGTH.
BIT_LENGTH (str)
Returns the binary length.
In summary, there are two functions in mysql to obtain the string length:
Length: returns the number of bytes occupied by a string. It is the length of a calculated field. One Chinese character is counted as three characters, and one digit or letter is counted as one character.
Char_length: returns the number of characters occupied by a string. It can be a single character, regardless of Chinese characters, numbers, or letters.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.