Beginner

241. LENGTH Function

Learn how to find the length of a text value.

📘 Lesson 241 of 728 ⏱ 8 min 🎯 Beginner

The LENGTH function returns the number of characters in a text value. The exact behavior with trailing spaces can vary between database systems.

String length is useful for validating, profiling, cleansing, and analyzing text data.

Find customers whose names contain more than 20 characters.

SQL
SELECT
    CustomerName,
    LENGTH(CustomerName) AS NameLength
FROM Customers;

LENGTH is useful for data validation, quality checks, identifying unusual values, and preparing text fields.

  • LENGTH returns the size of a text value.
  • It is useful for text validation.
  • It can help identify unusual records.
  • Database behavior can vary.
  • Some systems use LEN instead.
What does LENGTH do?

LENGTH returns the number of characters in a text value.

Why is LENGTH useful?

It can be used to validate text fields and identify unusually short or long values.

Have you finished this lesson?

Introduction to SQL – All Lessons