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 be used in the argument of other functions. For example, if we wanted to extract the approximate middle of a value, we could divide the length by four and cull out everything from the one fourth...