Skip to content
Related Articles

Related Articles

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 :



REVERSE(“GFG”)
GFG

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 :

result
Palindrome

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :