The SQLite length
function returns the number of characters of a string. If the argument is a BLOB, the length
function returns the number of bytes.
Syntax
length(data)
Code language: SQL (Structured Query Language) (sql)
Arguments
The length
function accepts one argument which can be a string or a BLOB.
data
The string or a BLOB argument.
If data is NULL, the length function returns NULL. If data is not text value, the length function will convert it to a text value first.
Return Type
INTEGER
Examples
The following statement returns the number of characters in the SQLite string:
SELECT length('SQLite');
Code language: SQL (Structured Query Language) (sql)
length('SQLite')
----------------
6
Code language: JavaScript (javascript)
The following query sorts the titles of albums by the title length in the descending order.
SELECT title,
length(title)
FROM albums
ORDER BY length(title) DESC;
Code language: SQL (Structured Query Language) (sql)
Was this tutorial helpful ?