MySQL REVERSE() function
In this context, we will learn how we can use the MySQL REVERSE() function with proper syntax and good examples.
Introduction of MySQL REVERSE() function
This function could be used to reverse a string and find the result. The REVERSE() function takes the input parameter as a string and results in the reverse order of that string.
Syntax of the MySQL REVERSE() function
The syntax of the MySQL REVERSE() function is given as follows:
SELECT REVERSE(string)
Parameters or arguments used in MySQL REVERSE() function:
There is only one parameter accepted by the REVERSE() function in MySQL, which is given as follows:
String- It is the string that will be reversed.
Returns:
It will return a string to find a string.
Application used for REVERSE() function:
The REVERSE() function can be used in the given below MySQL versions.:
- MySQL 5.7
- MySQL 5.6
- MySQL 5.5
- MySQL 5.1
- MySQL 5.0
- MySQL 4.1
- MySQL 4.0
- MySQL 3.23
Examples of MySQL REVERSE() function:
Now we will look into some MySQL REVERSE() function examples and will explore how we can use the REVERSE function in MySQL.
Example-1:
We will use the REVERSE function in this example to reverse a string.
SELECT REVERSE("JTP");
Output:
REVERSE(“JTP”)
PTJ
1 row in set (0.00 sec)
Example-2:
We will use the REVERSE function in this example to reverse a string.
SELECT REVERSE("JAVATPOINT");
Output:
REVERSE(“JAVATPOINT”);
TNIOPTAVAJ
1 row in set (0.00 sec)
Example-3:
In this example, we will use the REVERSE function to reverse a sentence :
SELECT REVERSE("JAVATPOINT is an interesting site");
Output:
REVERSE(“JAVATPOINT is an interesting site”)
etis gnitseretni na si TNIOPTAVAJ
1 row in set (0.00 sec)
Example-4:
Now we will use the REVERSE() function to find if a string is a Palindrome :
DECLARE
@input VARCHAR(100) = 'madam';
SELECT
CASE
WHEN @input = REVERSE(@input)
THEN 'Palindrome'
ELSE 'Not Palindrome'
END result;
Output:
result
Palindrome
1 row in set (0.00 sec)
Application of MySQL REVERSE() function:
This function is used to reverse a string and find the result.
Summary:
In the above context, we have learned how we can use the REVERSE() function in MySQL used to reverse a string and find the result.