In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain in detail how to query character length in mysql. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Methods: 1, the use of length () function query, the unit is bytes, a Chinese character is three bytes, the array and letters are a byte, the syntax is "length (character)"; 2, the use of "char_length ()" function query, units for characters, Chinese characters, numbers and letters are a character unit.
The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.
Take a look at the difference between length () and char_length () in Mysql.
1), length (): the length () function in mysql is a built-in function to get the length of a string.
2), char_length (): another function to check the string length in the mysql built-in function is char_length ().
3) the difference between the two functions is:
A), length (): units are bytes, under utf8 coding, a Chinese character has three bytes, a number or letter a byte. Under gbk coding, a Chinese character has two bytes, a number or letter a byte.
B), char_length (): units are characters, no matter Chinese characters or numbers or letters are considered as a character.
To expand, the change in varchar type since the MySQL5.0.3 version.
1), before MySQL 5.0.3: 0Murray 255 bytes, for example, 20 in varchar (20) indicates the number of bytes, if you store utf-8 code, you can only put 6 Chinese characters. Varchar (n), where n represents the number of bytes.
After MySQL 5.0.3: 0Mui 65535 bytes, varchar (20) represents the number of characters, no matter what kind of coding, both Chinese characters can also put 20. But it takes up to 65532 bytes (two bytes are stored in length, less than 255bytes are stored in one byte). The n here in varchar (n) represents the number of characters, such as varchar. Other specific differences can be queried online by yourself.
4. Length () char_length (), which can be used to check whether it contains Chinese characters.
In utf-8 coding, it is determined that a field is all English, and length (field) = char_length (field) is fine.
This is the end of this article on "how to query character length in mysql". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.