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.