MySQL CHARACTER_LENGTH(): Count Characters in a String

CHARACTER_LENGTH() returns the number of characters in a string. It is especially useful when text may contain multibyte characters, because LENGTH() counts bytes instead.

SELECT CHARACTER_LENGTH('Welcome to plus2net') AS characters;

The result is 19.

CHARACTER_LENGTH() vs LENGTH()

For ordinary ASCII text the values are often the same. For multibyte text they can differ.

SELECT LENGTH(_utf8mb4 '€') AS bytes,
       CHARACTER_LENGTH(_utf8mb4 '€') AS characters;
bytescharacters
31
CHAR_LENGTH() is a synonym for CHARACTER_LENGTH(). Use LENGTH() when you actually need byte length.

Length of values stored in a column

A VARCHAR(100) column can store values up to its declared character limit, but individual rows may use fewer characters. Measure the stored value directly:

SELECT CHARACTER_LENGTH(title) AS character_count, title
FROM photo_img
WHERE img_id = 47;

To find the longest titles:

SELECT CHARACTER_LENGTH(title) AS character_count, title
FROM photo_img
ORDER BY character_count DESC;

You can also filter by character length:

SELECT title
FROM photo_img
WHERE CHARACTER_LENGTH(title) > 50
ORDER BY CHARACTER_LENGTH(title) DESC;

All String Functions · CHAR_LENGTH() · LENGTH() · SUBSTRING() · SUBSTRING_INDEX()




Subscribe to our YouTube Channel here



plus2net.com




SQL Video Tutorials










✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer