REVERSE()
Returns the characters of a string in reverse order.
Description
REVERSE flips a string so its last character becomes the first. It's useful
for palindrome checks, reversing encoded values, or pulling a suffix when you
don't know its length (reverse, take from the left, reverse back).
Syntax
REVERSE(string)Parameters
| Name | Description | Optional |
|---|---|---|
| string | The text to reverse. | No |
Return Type
Returns a VARCHAR.
Examples
Employees & Departments
Loading database engine...
Employees & Departments
Loading database engine...
Grab a trailing segment
To take the last N chars without knowing the length: REVERSE(LEFT(REVERSE(s), N)).
Common Mistakes
- Reversing numbers as text.
REVERSEworks on strings; cast numbers to text first if you mean to reverse their digits. - Expecting word reversal. It reverses characters, not words.
- Unicode surprises. Some engines reverse by code point, which can look odd for multi-byte characters.
Related Functions
See also: SUBSTRING, LENGTH, CONCAT.