LENGTH(str)
Returns the length of the string str
, measured in bytes. A multi-byte character counts as multiple bytes. This means that for a string containing five two-byte characters, LENGTH() returns 10, whereas CHAR_LENGTH() returns 5.
If str
is not a string value, it is converted into a string. If str
is NULL
, the function returns NULL
.
Until MariaDB 10.3.1, returns MYSQL_TYPE_LONGLONG
, or bigint(10), in all cases. From MariaDB 10.3.1, returns MYSQL_TYPE_LONG
, or int(10), when the result would fit within 32-bits.
When running Oracle mode from MariaDB 10.3, LENGTH()
is a synonym for CHAR_LENGTH()
.
SELECT LENGTH('MariaDB'); +-------------------+ | LENGTH('MariaDB') | +-------------------+ | 7 | +-------------------+ SELECT LENGTH('π'); +--------------+ | LENGTH('π') | +--------------+ | 2 | +--------------+
In Oracle mode from MariaDB 10.3:
SELECT LENGTH('π'); +--------------+ | LENGTH('π') | +--------------+ | 1 | +--------------+
© 2019 MariaDB
Licensed under the Creative Commons Attribution 3.0 Unported License and the GNU Free Documentation License.
https://mariadb.com/kb/en/length/