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
Syntax
length(X)
Parameters
| Parameter | Description |
|---|---|
X |
A string, number or BLOB. |
Return value
An integer, or NULL.
Examples
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
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
LENGTH()· PostgreSQL
Related
OCTET_LENGTH()· Return the number of bytes a string takes in the database encoding (usually UTF-8), not the number of characters.SUBSTR()· Return part of a string starting at a 1-based position, with an optional length. Negative starts count from the end.- SQL String Functions · tutorial