Returns a string or an array in reverse order.
Syntax
string|array reverse(string|array <value>)
Parameters
value: required. A value of the STRING or ARRAY data type. If the input value is of the BIGINT, DOUBLE, DECIMAL, or DATETIME type, the input value is implicitly converted into a value of the STRING type before calculation.
Return value
A value of the STRING or ARRAY type is returned. The return value varies based on the following rules:
If the input value specified by value cannot be converted into a value of the STRING or ARRAY type, an error is returned.
If the value parameter is null, null is returned.
Examples
Example 1: Return a string whose characters are in reverse order of the string
I love aliyun very much
. Sample statement:-- The return value is hcum yrev nuyila evol I. select reverse('I love aliyun very much');
Example 2: An input parameter is set to null. Sample statement:
-- The return value is null. select reverse(null);
Example 3: Return an array whose elements are in reverse order of the array
[2, 1, 4, 3]
. Sample statement:-- The return value is [3, 4, 1, 2]. SELECT reverse(array(2, 1, 4, 3));
Related functions
REVERSE is a string function. For more information about functions related to string searches and conversion, see String functions.