Differences between mysql String length functions char_length, length, and bit_length

Source: Internet
Author: User
MysqlGBK encoding is equivalent to Chinese or Spanish characters, so the total number of characters is 2selectchar_length (character). One Chinese Character occupies 2 bytes, therefore, the total length of the byte is 4 selectlength (character); 1 English character occupies 1 byte, so the total length of the byte is 5 selectlength (china); 1 Chinese Character occupies 2 bytes, 1

Mysql GBK encoding is equivalent to Chinese or Spanish characters, so the total number of characters is 2 select char_length (character); 1 Chinese Character occupies 2 bytes, therefore, the total byte length is 4 select length (characters); 1 English character occupies 1 byte, so the total byte length is 5 select length (china); 1 Chinese Character occupies 2 bytes, 1

Mysql

-GBK encoding --

-Both Chinese and Spanish characters are treated equally, so the total number of characters is 2.
Select char_length ('characters ');

-One Chinese Character occupies 2 bytes, so the total length of the byte is 4.
Select length ('characters ');

-One English character occupies 1 byte, so the total length of the byte is 5.
Select length ('China ');

-One Chinese Character occupies 2 bytes, and one byte occupies 8 digits, so the total bit length is 32
Select bit_length ('characters ');

-- UTF-8 coding --

-Both Chinese and Spanish characters are treated equally, so the total number of characters is 2.
Select char_length ('characters ');

-One Chinese Character occupies three bytes, so the total length of the byte is 6.
Select length ('characters ');

-One English character occupies 1 byte, so the total length of the byte is 5.
Select length ('China ');

-One Chinese Character occupies 3 bytes, and one byte occupies 8 digits, so the total bit length is 48.
Select bit_length ('characters ');

Original article address: mysql String length functions char_length, length, bit_length difference, thank you for sharing.

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.