Open In App

REVERSE() Function in MySQL

Last Updated : 31 Aug, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads