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

How to calculate the length of data by mysql

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

Editor to share with you mysql how to find the length of the data, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!

Mysql data length method: 1, use the "LENGTH" function to get the string length, syntax such as "SELECT LENGTH ('character')"; 2, through the "CHAR_LENGTH" function to view the string length, syntax such as "SELECT CHAR_LENGTH ('character')".

MySql calculates the length of the field

User account has useful Chinese characters. Find all accounts that contain Chinese characters.

SELECT member_name FROM table_member WHERE length (member_name)! = char_length (member_name) LENGTH

The "LENGTH" function in mysql is a built-in function to get the length of a string.

CHAR_LENGTH

Another function that looks at the string length in the mysql built-in function is "CHAR_LENGTH". The difference between the two functions is:

LENGTH: a Chinese character is counted as three characters, and a number or letter as a character.

CHAR_LENGTH: whether a Chinese character or a number or a letter is a character

Example

Chinese characters

SELECT LENGTH ('character'); output: 6SELECT CHAR_LENGTH ('character'); output: 2

Character

SELECT LENGTH ('abc'); output: 3SELECT CHAR_LENGTH (' abc'); output: 3 command units, one Chinese character, one numeric or letter example char_length character 11char_length (str) lengthByte31length (str) bit_lengthbit248length (str)

When the length of the string exceeds the maximum length defined by max_allowed_packet, the above function returns NULL.

Max_allowed_packet generally defaults to 4MB (5.6.5 and below is 1MB)

These are all the contents of how mysql calculates the length of the data. Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more 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