SQLite length() Function

The SQLite length() function returns the number of characters in a given string, or return the number of bytes in a given blob value.

Syntax

Here is the syntax of the SQLite length() function:

length(x)

Parameters

x

Required. A string or blob value.

Return value

The SQLite length() function returns an integer value. For a string parameter, length() returns the number of characters in the string; for a blob parameter, length() returns the number of bytes in the blob.

Examples

To get the number of characters in the string hello, use the following statement with the length() function:

SELECT length('hello');
length('hello')
---------------
5

The SQLite length() function supports multi-byte literals. For example, to get the number of characters in 你好, use the following statement with the length() function:

SELECT length('你好');
length('你好')
------------
2

For a blob parameter, length() returns the number of bytes in the blob, for example:

SELECT length(cast('你好' AS blob));
length(cast('你好' AS blob))
--------------------------
6