Retrieve 4 characters from the right side of a string.
SELECT RIGHT(“SQL Tutorial is cool”, 4) AS ExtractString; |
The RIGHT() function retrieves a specified number of characters from a string, starting from the right.
Tip: Additionally, consider the LEFT() function for a similar operation.
RIGHT(string, number_of_chars) |
Parameter |
Description |
string |
Input required: The string from which extraction will be done. |
number_of_chars |
Input required: The number of characters to be extracted. If this parameter exceeds the number of characters in the string, the function will return the entire string. |
Works in: | From MySQL 4.0 |
Retrieve 5 characters from the right side of the text in the “CustomerName” column.
SELECT RIGHT(CustomerName, 5) AS ExtractString FROM Customers; |