SQLite 3 reference · String Functions

SQLite LENGTH() Function

Return the number of characters in a string, or the number of bytes in a BLOB. NULL gives NULL.

SQLite 3

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

length(X)

Parameters

ParameterDescription
X A string, number or BLOB.

Return value

An integer, or NULL.

Examples

Longest namesTry it yourself
SELECT name, length(name) AS letters
FROM customers
ORDER BY letters DESC
LIMIT 3;

Output

name | letters
Yukihiro Matsumoto | 18
Margaret Hamilton | 17
Katherine Johnson | 17
Characters vs bytes, and NULLTry it yourself
SELECT length('café') AS chars, octet_length('café') AS bytes, length(NULL) AS null_input;

Output

chars | bytes | null_input
4 | 5 | NULL

For numbers, length() measures their text form: length(3.50) is 3 because the value is stored as 3.5.

In other languages

Was this page helpful?