Return the length of a string in bytes. This function counts the number of bytes in the string, which may differ from character count for multi-byte strings.
Returns the length of the string str.
In the default mode, when is not set, the length is measured in bytes. In this case, a multi-byte character counts as multiple bytes. This means that for a string containing five two-byte characters, LENGTH() returns 10, whereas returns 5.
When running Oracle mode, the length is measured in characters, and LENGTH is a synonym for .
If str is not a string value, it is converted into a string. If str is NULL, the function returns NULL.
When Oracle mode is not set:
In Oracle mode:
This page is licensed: GPLv2, originally from
LENGTH(str)SELECT LENGTH('MariaDB');
+-------------------+
| LENGTH('MariaDB') |
+-------------------+
| 7 |
+-------------------+SELECT CHAR_LENGTH('Ï€'), LENGTH('Ï€'), LENGTHB('Ï€'), OCTET_LENGTH('Ï€');
+-------------------+--------------+---------------+--------------------+
| CHAR_LENGTH('Ï€') | LENGTH('Ï€') | LENGTHB('Ï€') | OCTET_LENGTH('Ï€') |
+-------------------+--------------+---------------+--------------------+
| 1 | 2 | 2 | 2 |
+-------------------+--------------+---------------+--------------------+SELECT CHAR_LENGTH('Ï€'), LENGTH('Ï€'), LENGTHB('Ï€'), OCTET_LENGTH('Ï€');
+-------------------+--------------+---------------+--------------------+
| CHAR_LENGTH('Ï€') | LENGTH('Ï€') | LENGTHB('Ï€') | OCTET_LENGTH('Ï€') |
+-------------------+--------------+---------------+--------------------+
| 1 | 1 | 2 | 2 |
+-------------------+--------------+---------------+--------------------+