The two functions mysqllength and char_length must be familiar to everyone, but there should be very few people who know the difference between them. in this article, I would like to introduce to coders what is the difference between mysqllength and char_length and what is the difference? For more information, see. Length: the length of a calculated field. a Chinese character is counted as three characters. a number or letter is counted as one character.
Char_length: whether it is a Chinese character, a number, or a letter.
Example:
1. the data you want to query contains three characters in English. for this query, you need to use the mysql function of length, length is the length of a calculated field. a Chinese character is counted as three characters, and a number or letter is counted as one character.
Select * from user where length (username) = 3
In this way, the query results will show all the username fields with three characters, and no username with three Chinese characters will appear.
2. if you want to query a field that occupies three positions, you should use char_length for query, this function is a single character, regardless of Chinese characters, numbers, or letters,
Select * from user where char_length (username) = 3
Length: indicates the length of a calculated field. a Chinese character can contain three or four characters. it depends on the encoding of your database. a number or letter can be a character.
Note that for multi-byte characters, its CHAR_LENGTH () is calculated only once.
SELECT Name, CHAR_LENGTH (Name) AS CharLengthFROM DVDsWHERE CHAR_LENGTH (Name)> 5 order by Name;