SQLite 3 reference · String Functions
SQLite OCTET_LENGTH() Function
Return the number of bytes a string takes in the database encoding (usually UTF-8), not the number of characters.
SQLite 3 Since 3.43.0
Syntax
octet_length(X)
Parameters
| Parameter | Description |
|---|---|
X |
The string (other values are converted to text). |
Return value
An integer, or NULL.
Examples
SELECT octet_length('abc') AS ascii, octet_length('naïve') AS utf8;
Output
ascii | utf8 3 | 6
SELECT name, length(name) AS chars, octet_length(name) AS bytes
FROM customers
WHERE customer_id = 1;
Output
name | chars | bytes Ada Lovelace | 12 | 12
Version history
| Version | Change |
|---|---|
| SQLite 3.43.0 | Added |
In other languages
LENGTH()· PostgreSQL
Related
LENGTH()· Return the number of characters in a string, or the number of bytes in a BLOB. NULL gives NULL.- SQL String Functions · tutorial