REVERSE() Function in MySQL
Last Updated :
31 Aug, 2020
REVERSE() :
This function could be used to reverse a string and find the result. The REVERSE() function takes input parameter as string and results the reverse order of that string.
Syntax :
SELECT REVERSE(string)
Note –
The parameter string is mandatory, It is the string that will be reversed.
Example-1:
SELECT REVERSE("GFG");
Output :
Example-2:
Using REVERSE() function to reverse a string :
SELECT REVERSE("Geeksforgeeks");
Output :
REVERSE(“Geeksforgeeks”); |
skeegrofskeeG |
Using REVERSE() function to reverse a sentence :
SELECT REVERSE("Geeksforgeeks is an interesting site");
Output :
REVERSE(“Geeksforgeeks is an interesting site”) |
etis gnitseretni na si skeegrofskeeG |
Using REVERSE() function to find if a string is Palindrome :
DECLARE
@input VARCHAR(100) = 'madam';
SELECT
CASE
WHEN @input = REVERSE(@input)
THEN 'Palindrome'
ELSE 'Not Palindrome'
END result;
Output :
Share your thoughts in the comments
Please Login to comment...