REVERSE

REVERSE is a string function in SQL, primarily used to reverse the order of characters in a specified string expression. It returns the reversed version of the input string.

REVERSE(str)

  • str: The string value for which reverse operation is to be conducted. The REVERSE() function in MySQL uses this parameter to reverse the sequence of characters in a provided string.

Example

SELECT REVERSE('SQL');

Output

LQS

Explanation

The REVERSE function in MySQL is used to reverse a string. In the given example, it takes ‘SQL’ as an input and returns ‘LQS’.

REVERSE( string_expression )

  • string_expression: This parameter indicates the string that will be reversed by the function. It should be of a data type that is explicitly convertible to the varchar data type. The entire expression string is reversed including words and characters.

Example

SELECT REVERSE('Hello World') as ReversedString;

Output

dliroW olleH

Explanation

The REVERSE function in SQL Server flips the order of the characters in the input string. In the above example, ‘Hello World’ is reversed as ‘dliroW olleH’.

REVERSE(char)

  • char: This parameter specifies the string that you wish to reverse in Oracle. It refers to the character string which can be any of the datatypes CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB. The provided string is then processed by the REVERSE function to provide an output string that is a reversal of the input. This is read back from end to start. It is to be noted that the function returns a value that matches the datatype of the input string. If the input is NULL, the result is NULL.

Example

SELECT REVERSE('Oracle') FROM dual;

Output

elcarO

Explanation

The REVERSE function in Oracle SQL returns the input string reversed. In the given example, the string ‘Oracle’ is reversed to ‘elcarO’.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.