All Products
Search
Document Center

MaxCompute:REVERSE

Last Updated:Oct 23, 2025

The REVERSE function returns a string, binary data, or an array in reverse order.

Syntax

STRING|BINARY|ARRAY REVERSE(STRING|BINARY|ARRAY <value>)

Parameters

value: Required. A value of the STRING, BINARY, or ARRAY data type. If the input value is of a data type such as BIGINT, DOUBLE, DECIMAL, or DATETIME, it is implicitly converted to the STRING type before the operation is performed.

Return value

Returns a value of the STRING, BINARY, or ARRAY type. The data type of the return value is the same as that of the input parameter. The return value is determined by the following rules:

  • If the input value cannot be converted to the STRING, BINARY, or ARRAY type, an error is returned.

  • If the value parameter is null, null is returned.

Note
  • By default, the REVERSE function reverses data byte by byte.

  • If you run the SET odps.sql.bigquery.compatible=true; command to enable BigQuery compatibility mode, the REVERSE function reverses STRING data based on UTF-8 encoding, and reverses BINARY and ARRAY data byte by byte.

Examples

  • Example 1: Reverse the string I love aliyun very much.

    -- The return value is hcum yrev nuyila evol I.
    SELECT REVERSE('I love aliyun very much');
  • Example 2: The input parameter is NULL.

    -- The return value is NULL.
    SELECT REVERSE(null);
  • Example 3: Reverse the array [2, 1, 4, 3].

    -- The return value is [3, 4, 1, 2].
    SELECT REVERSE(ARRAY(2, 1, 4, 3));
  • Example 4: Reverse the binary data unhex('FA34E10293CB42848573A4E39937F479').

    -- The return value is y=F47=99=E3=A4s=85=84B=CB=93=02=E14=FA.
    SELECT REVERSE(UNHEX('FA34E10293CB42848573A4E39937F479'));
  • Example 5: Run the SET odps.sql.bigquery.compatible=true; command to enable BigQuery compatibility mode to process emoji characters.

    Important

    You can run the following command in the code editor of the MaxCompute client. For more information, see SQL code editor.

    1. In the bin folder of the MaxCompute client, create a source file named reverse_func.sql with the following content:

      SET odps.sql.bigquery.compatible=true;
      SELECT REVERSE("<Emoji character>");
    2. Open a command-line window, such as Command Prompt (CMD) on Windows. Go to the bin folder of the MaxCompute client and run the following command:

      odpscmd -s reverse_func.sql

      After the command runs successfully, you can view the reversed result on the Result tab in Logview.

Related functions

REVERSE is a string function. For more information about functions related to string searches and conversion, see String functions.