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:
EmpID | Name | City | Age | Salary |
---|---|---|---|---|
1 | John | London | 25 | 3000 |
2 | Marry | New York | 24 | 2750 |
3 | Jo | Paris | 27 | 2800 |
4 | Kim | Amsterdam | 30 | 3100 |
5 | Ramesh | New Delhi | 28 | 3000 |
6 | Huang | Beijing | 28 | 2800 |
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:
EmpID | Name | City | Age | REVERSE_String |
---|---|---|---|---|
1 | John | London | 25 | nodnoL |
2 | Marry | New York | 24 | kroY weN |
3 | Jo | Paris | 27 | siraP |
4 | Kim | Amsterdam | 30 | madretsmA |
5 | Ramesh | New Delhi | 28 | ihleD weN |
6 | Huang | Beijing | 28 | gnijieB |
❮ MariaDB Functions