Skip to content

OCTET_LENGTH

  • str: This is the string value that the OCTET_LENGTH() function will measure. It represents a sequence of characters whose length in octets or bytes you want to find.
SELECT OCTET_LENGTH('MySQL');
5

The OCTET_LENGTH function in MySQL is used to return the length of a given string, in bytes. In the above example, the string ‘MySQL’ consists of 5 characters, therefore, the output is 5. Please note that OCTET_LENGTH considers each character as one byte, so it doesn’t account for characters that use more than one byte such as special or Unicode characters.