Get the App
SLTechnology News&Howtos  ›  Database  › 

How to calculate the length of data by mysql

Shulou Source: shulou.com Published: 2022-06-01 02:10:22 10月01日 Update

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!

Tags: Character length function string Chinese character output data letter number content article grammar account number Chinese maximum three not much two unit command Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft vpn MariaDB MySQL Shulou Technology