MariaDB Tutorial MariaDB Advanced MariaDB Database Account Management MariaDB References

MariaDB REVERSE() Function



The MariaDB REVERSE() function returns a string with the characters in reverse order. This function is safe to use with a string containing multi-byte characters.

Syntax

REVERSE(string)

Parameters

string Required. Specify the string whose characters are to be reversed.

Return Value

Returns a string with the characters in reverse order of the specified string.

Example 1:

The example below shows the usage of REVERSE() function.

SELECT REVERSE('12345');
Result: '54321'

SELECT REVERSE('ABCDE');
Result: 'EDCBA'

SELECT REVERSE(12345);
Result: '54321'

SELECT REVERSE('Reverse this String');
Result: 'gnirtS siht esreveR'

Example 2:

Consider a database table called Employee with the following records:

EmpIDNameCityAgeSalary
1JohnLondon253000
2MarryNew York242750
3JoParis272800
4KimAmsterdam303100
5RameshNew Delhi283000
6HuangBeijing282800

The query mentioned below is used to reverse the records of City column.

SELECT *, REVERSE(City) AS REVERSE_String FROM Employee;

The query will produce the following result:

EmpIDNameCityAgeREVERSE_String
1JohnLondon25nodnoL
2MarryNew York24kroY weN
3JoParis27siraP
4KimAmsterdam30madretsmA
5RameshNew Delhi28ihleD weN
6HuangBeijing28gnijieB

❮ MariaDB Functions