REVERSE
Reverses the character order of a string or returns a NULL
if the parameter is NULL
.
Syntax
SELECT REVERSE(<string>);
Arguments
string: any string
Return Type
String
Examples
SELECT REVERSE('See the inventory list for details' collate utf8mb4_general_ci); **** +--------------------------------------------------------------------------+ | REVERSE('See the inventory list for details' collate utf8mb4_general_ci) | +--------------------------------------------------------------------------+ | sliated rof tsil yrotnevni eht eeS | +--------------------------------------------------------------------------+
In the examples below, the following table and values were used:
CREATE TABLE inventory(item_ID VARCHAR(25), item VARCHAR(50), category VARCHAR(25), cases_instock NUMERIC(4)); INSERT INTO inventory VALUES('GA001','Green Apples', 'fruit', '22'), ('RB247','Bananas', 'fruit','32'), ('GP749', 'Golden Pineapple', 'fruit', '11'), ('KM991', 'Kent Mango', 'fruit', '5'), ('FP860', 'Fuyu Persimmons', 'fruit','2');
SELECT item, REVERSE(item) FROM inventory; **** +------------------+------------------+ | item | REVERSE(item) | +------------------+------------------+ | Bananas | sananaB | | Green Apples | selppA neerG | | Fuyu Persimmons | snommisreP uyuF | | Kent Mango | ognaM tneK | | Golden Pineapple | elppaeniP nedloG | +------------------+------------------+
SELECT item_id, item, REVERSE(item_id), REVERSE(item) FROM inventory; **** +---------+------------------+------------------+------------------+ | item_id | item | REVERSE(item_id) | REVERSE(item) | +---------+------------------+------------------+------------------+ | GP749 | Golden Pineapple | 947PG | elppaeniP nedloG | | GA001 | Green Apples | 100AG | selppA neerG | | KM991 | Kent Mango | 199MK | ognaM tneK | | RB247 | Bananas | 742BR | sananaB | | FP860 | Fuyu Persimmons | 068PF | snommisreP uyuF | +---------+------------------+------------------+------------------+