Home  >  Article  >  Database  >  How to find the length of data in mysql

How to find the length of data in mysql

藏色散人
藏色散人Original
2020-10-27 10:28:276443browse

Mysql method to find the data length: 1. Use the "LENGTH" function to get the string length, with syntax such as "SELECT LENGTH('Character')"; 2. Check the string length through the "CHAR_LENGTH" function, The syntax is "SELECT CHAR_LENGTH('character')".

How to find the length of data in mysql

# Recommended: "

mysql video tutorial

MySql calculates the length of the field

User accounts have Chinese characters, find all accounts containing 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 used to obtain the length of a string

CHAR_LENGTH

View the string in the mysql built-in function There is also a length function called "CHAR_LENGTH". The difference between the two functions is:

LENGTH: A Chinese character counts as three characters, and a number or letter counts as one character.
CHAR_LENGTH: Whether it is Chinese characters, numbers or letters, it is considered a character


Example

Chinese characters

SELECT LENGTH('字符');
输出:6

SELECT CHAR_LENGTH('字符');
输出:2

Characters

SELECT LENGTH('abc');
输出:3

SELECT CHAR_LENGTH('abc');
输出:3

CommandUnitA Chinese characterA number or letterExampleCharacter11Byte31##bit_lengthlength(str)
char_length char_length(str)
length length(str)
bit 24 8
When the length of the string exceeds the maximum length defined by max_allowed_packet, the above function will return NULL .
max_allowed_packet generally defaults to 4MB (1MB for 5.6.5 and below)



The above is the detailed content of How to find the length of data in mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn