We need to pass the column name as argument to the OCTET_LENGTH() function to count the number of characters stored in the data column. It displays the number of characters when quoted in a SELECT clause. It can also be used as a comparison value to decide whether the row should be returned by using it in the WHERE clause. The contents of the ‘Student’ table are for demonstration -
mysql> Select Name, OCTET_LENGTH(Name)As 'Str_Length' from Student; +---------+------------+ | Name | Str_Length | +---------+------------+ | Gaurav | 6 | | Aarav | 5 | | Harshit | 7 | | Gaurav | 6 | | Yashraj | 7 | +---------+------------+ 5 rows in set (0.00 sec) mysql> Select Name, OCTET_LENGTH(Name)As 'Str_Length' from Student Where OCTET_LENGTH(Name) < 7; +--------+------------+ | Name | Str_Length | +--------+------------+ | Gaurav | 6 | | Aarav | 5 | | Gaurav | 6 | +--------+------------+ 3 rows in set (0.06 sec)
The above is the detailed content of How to use the MySQL OCTET_LENGTH() function to count the number of characters stored in a data column?. For more information, please follow other related articles on the PHP Chinese website!