SQL LENGTH
Return the number of characters in a text value.
Syntax
LENGTH(text)
Example
Query (on the shop database used in the SQL course)
SELECT name, LENGTH(name) AS letters FROM products ORDER BY letters DESC LIMIT 3;
Result
| name | letters |
|---|---|
| Noise-cancelling headphones | 27 |
| Python Crash Course (book) | 26 |
| Deep Learning (book) | 20 |
3 rows
Good to know. SQL Server calls it LEN.
Related
Learn it step by step in the free lesson Functions: Text, Numbers, Dates & CASE, with exercises that check your queries.