All Products
Search
Document Center

MaxCompute:URL_ENCODE

Last Updated:Mar 26, 2026

Encodes a string so it can be safely included in a URL query parameter name or value, following the application/x-www-form-urlencoded MIME format.

Syntax

string url_encode(string <input>[, string <encoding>])

Description

Applies percent-encoding to the input string according to the following rules:

  • Letters (a–z, A–Z) remain unchanged.

  • Periods (.), hyphens (-), asterisks (*), and underscores (_) remain unchanged.

  • Spaces are converted to plus signs (+).

  • All other characters are converted to their byte values using the specified encoding (UTF-8 by default), then represented as %XX, where XX is the uppercase hexadecimal byte value.

Parameters

Parameter Required Type Description
input Yes STRING The string to encode.
encoding No STRING The character encoding to use for byte conversion. Valid values: UTF-8 (default), GBK.

Return value

Returns a STRING value. Returns null if input or encoding is null.

Examples

-- Returns %E7%A4%BA%E4%BE%8Bfor+url_encode%3A%2F%2F+%28fdsf%29.
select url_encode('Example for url_encode:// (fdsf)');

-- Returns Example+for+url_encode+%3A%2F%2F+dsf%28fasfs%29.
select url_encode('Example for url_encode:// dsf(fasfs)', 'GBK');

Related functions

url_encode is a string function. For a full list of string functions, see String functions.