Beginner

196. LENGTH Function

Learn how to calculate the length of text values using SQL string functions.

📘 Lesson 196 of 728 ⏱ 8 min 🎯 Intermediate

The LENGTH function returns the number of characters in a text value in database systems that support this function. Some systems use functions such as LEN instead.

Text length checks are useful for validating data, identifying unusual values, and checking field quality.

Find customers whose names contain more than 20 characters.

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

Length functions are useful for data validation, cleansing, identifier checks, and quality-control processes.

  • LENGTH calculates text length in supported systems.
  • Function names can vary between databases.
  • It is useful for data-quality checks.
  • It can be used in filtering.
  • It can be combined with other string functions.
What does LENGTH do?

It returns the length of a text value in database systems that support the function.

Is LENGTH available with exactly the same name everywhere?

No. Some database systems use different functions, such as LEN.

Have you finished this lesson?

Introduction to SQL – All Lessons