O'Reilly logo

MySQL for Python by Albert Lukaszewski, PhD

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 |

The LENGTH() function can similarly ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required