This article will introduce in detail the usage differences between mysqllength and char_length. For more information, see.
This article will introduce the usage differences between mysql length and char_length in detail. 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.
The Code is as follows: |
|
* 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,
The Code is as follows: |
|
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 your encoding. A number or letter can contain one character.
Note that for multi-byte characters, its CHAR_LENGTH () is calculated only once.
The Code is as follows: |
|
SELECT Name, CHAR_LENGTH (Name) AS CharLength FROM DVDs WHERE CHAR_LENGTH (Name)> 5 Order by Name; |