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

How to find the length of data in mysql

藏色散人
Release: 2020-10-29 16:52:13
Original
6467 people have browsed it

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)
Copy after login

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
Copy after login

Characters

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

SELECT CHAR_LENGTH('abc');
输出:3
Copy after login
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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template