MySQL Get string length function (char_length)

Source: Internet
Author: User


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

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.