Mysql returns the string length function (CHAR_LENGTH) _ MySQL
Source: Internet
Author: User
Mysql returns the string length function (CHAR_LENGTH) bitsCN. comlength: calculates the length of a field. a Chinese character is counted as three characters, and 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
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. bitsCN.com is a single character, regardless of Chinese characters, numbers, or letters.
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