Updated on 2026-11-06 GMT+08:00

reverse

The reverse function is used to return the reversed string.

Syntax

reverse(string ) 

Parameters

Parameter

Mandatory

Type

Description

str

Yes

STRING

The string to be reversed. If the input is of type BIGINT, DOUBLE, DECIMAL, or DATETIME, it is implicitly converted to STRING type before evaluation.

Return Values

Returns STRING type.

  • If str is not of type STRING, BIGINT, DOUBLE, DECIMAL, or DATETIME, an error is returned.
  • If str is NULL, NULL is returned.

Example Code

Returns LQS krapS.

SELECT reverse('Spark SQL');  

Returns [3,4,1,2].

SELECT reverse(array(2, 1, 4, 3));