All Products
Search
Document Center

MaxCompute:ENCODE

Last Updated:Aug 01, 2023

Encodes string str in the format specified by charset.

Syntax

binary encode(string <str>, string <charset>)

Parameters

  • str: required. A value of the STRING type. This parameter specifies the string that you want to encode.

  • charset: required. A value of the STRING type. This parameter specifies the encoding format. Valid values: UTF-8, UTF-16, UTF-16LE, UTF-16BE, ISO-8859-1, and US-ASCII.

    Note

    Currently, the ISO-8859-1 and US-ASCII encoding formats can be used to encode or decode only English characters.

Return value

A value of the BINARY type is returned. If the value of str or charset is null, null is returned.

Examples:

  • Example 1: Encode string abc in the UTF-8 format. Sample statement:

    -- The return value is abc. 
    select encode("abc", "UTF-8");
  • Example 2: Encode string abc in the UTF-16BE format. Sample statement:

    -- The return value is =00a=00b=00c. 
    select encode("abc", "UTF-16BE");
  • Example 3: An input parameter is set to null. Sample statement:

    -- The return value is null. 
    select encode("abc", null);

Related functions

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