Skip to main content

OCTET_LENGTH

Returns the number of bytes in the encoding of a string, where LENGTH counts characters.

See also:
[SELECT] [LENGTH]


Syntax​

SELECT OCTET_LENGTH(string) FROM <multipartIdentifier>;

Arguments​

string
A string or BLOB. A number is measured in its text form.

Return Value(s)​

Returns an integer. The result is NULL if string is NULL.


Examples​

Characters and bytes​

The accented character takes two bytes in UTF-8:

SELECT LENGTH('héllo') AS chars, OCTET_LENGTH('héllo') AS bytes;
|-------|-------|
| bytes | chars |
|-------|-------|
| 6 | 5 |
|-------|-------|

For more information, see https://www.sqlite.org/lang_corefunc.html#octet_length