September 2010
Intermediate to advanced
440 pages
9h 23m
English
Here you will see how to calcualte the length of a value with LENGTH() function.
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 | +-------------------+--------------+ ...
Read now
Unlock full access