The LENGTH function returns the number of characters in a string. Exact behavior can differ depending on the database and character encoding.
String length checks are useful for validating identifiers, phone numbers, codes, names, and imported text data.
Find customers whose names contain more than 20 characters.
SELECT
CustomerName,
LENGTH(CustomerName) AS NameLength
FROM Customers;
LENGTH is useful in data-quality checks, validation, cleansing, and text analysis.
- LENGTH measures string length.
- It can support data validation.
- It is useful for identifying unusual values.
- Character-count behavior can vary.
- Some databases use LEN instead.
What does LENGTH return?
LENGTH returns the number of characters in a string according to the database's string-length rules.
How can LENGTH help with data quality?
It can identify values that are unexpectedly short, long, or inconsistent with expected formats.