Accessing and using index data

Here you will see how to calcualte the length of a value with LENGTH() function.

LENGTH()

Like len() in Python, the LENGTH() function of MySQL returns the bitwise length of the value that is passed to it. Where multi-byte characters are used in the argument, multiple byte values are tabulated. Therefore, in sakila, we can retrieve the title and length of the title for each film. Here we use a WHERE clause to limit the results for the sake of space.

SELECT title as title, LENGTH(title) as title_length FROM film WHERE title LIKE 'TA%E';
+-------------------+--------------+
| title      | title_length |
+-------------------+--------------+
| TALENTED HOMICIDE |     17 |
| TARZAN VIDEOTAPE |     16 |
+-------------------+--------------+ ...

Get MySQL for Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.