The LENGTH function returns the number of characters or bytes in a text value depending on the database system and function implementation. Some database systems use functions such as LEN or LENGTH for this purpose.
Text length checks are useful for data-quality analysis. Analysts can identify unusually short, long, incomplete, or incorrectly formatted values.
An analyst may want to identify employee names that contain fewer than three characters or customer codes that do not have the expected length.
SELECT
EmployeeName,
LENGTH(EmployeeName) AS NameLength
FROM Employees;
LENGTH is useful for data validation, customer data cleaning, code validation, address analysis, and text profiling.
- LENGTH measures the size of a text value.
- Function names can vary between databases.
- It is useful for data-quality checks.
- It can help identify unexpected text lengths.
- It can be used inside SQL expressions.
What does LENGTH do in SQL?
LENGTH returns the length of a text value according to the database system's implementation.
Is LENGTH named the same in every database?
No. Some systems use LENGTH while others provide functions such as LEN.