Beginner

97. LENGTH Function

Learn how to determine the length of a text value.

📘 Lesson 97 of 728 ⏱ 7 min 🎯 Beginner

A string length function returns the number of characters in a text value. The exact function name can vary between SQL database systems, such as LENGTH or LEN.

Checking text length is useful for data validation, identifying invalid values, and understanding the structure of text fields.

An analyst can check whether customer codes have the expected number of characters.

SQL
SELECT
    EmployeeName,
    LENGTH(EmployeeName) AS NameLength
FROM Employees;

Length checks are useful for validating account numbers, postal codes, phone numbers, customer IDs, employee codes, and other text fields.

  • String length functions count characters.
  • Function names vary between database systems.
  • LENGTH is common in several SQL systems.
  • SQL Server commonly uses LEN.
  • Length checks are useful for data validation.
What does a string length function do?

It returns the number of characters in a text value.

Is the length function identical in every database?

No. Different database systems may use different function names or have different behavior.

Have you finished this lesson?

Introduction to SQL – All Lessons