Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Which is the function of mysql to find the length?

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces which is the function of mysql to find the length. It is very detailed and has a certain reference value. Friends who are interested must read it!

The mysql function for length is the length () function and the char_length () function; where the length () function returns the length of a string in bytes, and the char_length () function returns the length of a string in characters.

Both char_length function and length function in MySQL can return the length of a string.

Mysql > select length ('MySQL'), char_length (' MySQL') +-+-+ | length ('MySQL') | char_length (' MySQL') | +-+-+ | 5 | +- -+-+ 1 row in set (0.01 sec)

The functions of the two functions:

LENGTH () returns the length of the string in bytes.

CHAR_LENGTH () returns the length of a string in characters.

Judging from the above example, "MySQL" has a total of 5 characters, and each character should occupy 1 byte.

While Chinese is different, generally a Chinese character accounts for 2-3 bytes. Such as:

Under the GBK character set encoding:

Select char_length ('China'); / / 2 characters select length ('China'); / / 4 bytes, a Chinese character 2 bytes select bit_length ('China'); / / 32 bits. 4: 8 = 32

Under the UTF8 character set encoding:

Select char_length ('China'); / / 2 characters select length ('China'); / / 6 bytes, a Chinese character 3 bytes select bit_length ('China'); / / 48 bits. 6 8 = 48

Summary

Char_length (str)

The unit of length is a character, and a multi-byte character counts as a single character.

Whether a Chinese character or a number or a letter is a character.

Length (str)

Under utf8 coding, a Chinese character is counted as three characters, and a number or letter as a character.

Under other codes, a Chinese character is counted as two characters, and a number or letter as a character.

The above is all the contents of which is the function of mysql to find the length. Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report