MySQL REVERSE() Function

The REVERSE() function in MySQL reverses the order of characters in a string. This is a simple yet useful function for various text manipulation tasks.



REVERSE(): Definition and Usage

REVERSE() takes a string as input and returns a new string with the characters in the opposite order. It's a straightforward way to flip the sequence of characters. This can be helpful for creating reversed strings for specific applications or for simply reversing the character order for display or analysis purposes.

Syntax

Syntax

REVERSE(string)
      

Parameter Values

Parameter Description
string The string you want to reverse. This is required.

Examples

Reversing a String Literal

This example reverses the string "SQL Tutorial".

Syntax

SELECT REVERSE("SQL Tutorial");
      
Output

lairotuT LQS
      

Reversing Strings from a Column

This example reverses the 'CustomerName' for each customer in the 'Customers' table (assuming a table named 'Customers' exists with a 'CustomerName' column).

Syntax

SELECT REVERSE(CustomerName)
FROM Customers;
      
Output

(The reversed CustomerNames from the Customers table will be displayed here.)
      

**Note:** The second example's output will depend on the data in your `Customers` table. Each row will show the `CustomerName` reversed.