MySQL OCTET_LENGTH Function

MySQL OCTET_LENGTH is a synonym of the LENGTH function. This OCTET LENGTH String method is used to find the length of a user-given expression, and the syntax of this function is as shown below:

SELECT OCTET_LENGTH(String_Expression) FROM Source

MySQL OCTET_LENGTH Function Example

The String OCTET LENGTH function counts and returns the number of characters inside a given expression. The following query shows multiple ways to use this OCTET_LENGTH method.

SELECT OCTET_LENGTH('Hello');

SELECT OCTET_LENGTH('Tutorial Gateway');

SELECT OCTET_LENGTH('MySQL Tutorial');
MySQL OCTET_LENGTH Example

Remember, the OCTET_LENGTH String Function counts the empty space as well. Please refer to the LENGTH method. Here, we are using this MySQL function on a table. In this example, we are going to find the Octet length of the Department Name column and Email column.

SELECT FirstName,
LastName,
DepartmentName,
OCTET_LENGTH(DepartmentName) AS DeptLen,
Email,
OCTET_LENGTH(Email) AS EmailLen
FROM `MySQL Tutorial`.employe;
MySQL OCTET_LENGTH Function 2