Length: is a calculation of the lengths of a field a Chinese character is counted three characters, a number or letter is counted as a character
The Char_length (str) return value is the length of the string str, and the length of the unit is a character. A multibyte character counts as a single word. For one containing five two-byte character sets, the LENGTH () return value is 10, and the return value of Char_length () is 5.
Character_length (str) character_length () is a synonym for Char_length ().
Bit_length (str) returns 2 in length.
For example, you can find a list of users with a user name that is less than 6 characters long.
Sql
The code is as follows |
Copy Code |
SELECT * from admin WHERE LENGTH (username) < 6 |
Char_length (str)
The return value is the length of the string str, and the length of the unit is a character. A multibyte character counts as a single word. For one containing five two-byte character sets, the LENGTH () return value is 10, and the return value of Char_length () is 5.
Character_length (str)
Character_length () is a synonym for Char_length ().
Bit_length (str)
Returns the 2 feed length.
In a nutshell, there are two functions in MySQL to get the length of a string:
Length: Returns the number of bytes in the string, which is the length of the calculated field. A Chinese character is counted as three characters, a digit or letter is counted as a character
Char_length: Returns the number of characters in a string, whether kanji or digit or letter is a character