Previous Next JavaScript must be enabled to correctly display this content

## reverse Function

The reverse function returns the characters of the source string in reverse order, where the string is written beginning with the last character first. For example, the reverse order for "welcome" is "emoclew".

Syntax

    returnvalue reverse(source)

    source ::= any*
    returnvalue ::= string

Semantics

source

  The input string for which the characters should be reversed. This argument is implicitly cast to a sequence of strings.

returnvalue

  Returns NULL if the source argument is NULL.

  Returns NULL if the source argument is an empty sequence or a sequence with more than one item.

Example 12-68 reverse Function

In this example, the first name is displayed along with its reverse order.

    SELECT firstname, reverse(firstname) FROM users

Output:

     +-----------+----------+
     | firstname | Column_2 |
     +-----------+----------+
     | John      | nhoJ     |
     | Peter     | reteP    |
     | Mary      | yraM     |
     +-----------+----------+