MySQL

MySQL RIGHT() Function

In SQL language the RIGHT() function allows extracting the end of a string by defining the desired length. The function allows truncating a string from the end, on the desired number of characters.
 

Syntax:

The function is used in a SQL query according to the following syntax:

SELECT RIGHT(str, length);

The “str” string refers to the input string, while the “length” parameter is a number that refers to the maximum length of the output string.
 

 

Example :

The queries below show RIGHT() function in several typical usage examples with their results:

SELECT RIGHT('HelloWorld', 3);  -- output: 'rld'
SELECT RIGHT('HelloWorld', 50); -- output: 'HelloWorld'
SELECT RIGHT('HelloWorld', 0);  -- output: ''
SELECT RIGHT('HelloWorld', -1); -- output: ''
SELECT RIGHT('HelloWorld', NULL); -- output: NULL

The examples show that the result returns the end of the strings and will never exceed the specified number of characters. Moreover, if the input string is smaller than the limit, the result will not be truncated.

mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *