MySQL returns the specified number of characters in a string with the help of the LEFT() and RIGHT() functions.
MySQL LEFT() function will return the specified number of characters from the left side of the string.
LEFT(str, length)
Here str is a string of multiple characters to be returned, and the length is an integer value specifying the number of characters to be returned.
mysql> Select LEFT('My Name is Ram', 7); +---------------------------+ | LEFT('My Name is Ram', 7) | +---------------------------+ | My Name | +---------------------------+ 1 row in set (0.00 sec)
The MySQL RIGHT() function will return the specified number of characters from the right side of a string.
RIGHT(str, length)
Here str is a string of multiple characters to be returned, and the length is an integer value specifying the number of characters to be returned.
mysql> Select RIGHT('My name is Ram',6); +---------------------------+ | RIGHT('My name is Ram',6) | +---------------------------+ | is Ram | +---------------------------+ 1 row in set (0.00 sec)
The above is the detailed content of Which MySQL function returns a specified number of strings as output?. For more information, please follow other related articles on the PHP Chinese website!