URL_ENCODE

Updated at:

URL_ENCODE encodes a string in the application/x-www-form-urlencoded MIME format and returns the encoded result. Returns NULL if the input contains invalid values or the encoding is not supported.

Limits

Supported only in Realtime Compute for Apache Flink that uses Ververica Runtime (VVR) 8.0.8 or later.

Syntax

VARCHAR URL_ENCODE(VARCHAR input)
VARCHAR URL_ENCODE(VARCHAR input, VARCHAR encoding)

Parameters

Parameter Data type Required Default Description
input VARCHAR Yes — The string to encode.
encoding VARCHAR No UTF-8 Optional. The character encoding to use, such as GBK or UTF-8.

Return type

VARCHAR

Examples

Encode with default UTF-8 encoding

Test data (T1)

id (INT) input (VARCHAR)
1 http://calcite.apache.org
2 http://test?a=b&c=d
3 http://你好
4 test

Test statement

SELECT
    id,
    URL_ENCODE(input) AS `value`
FROM
    T1;

Test result

id (INT) value (VARCHAR)
1 https%3A%2F%2Fcalcite.apache.org
2 http%3A%2F%2Ftest%3Fa%3Db%26c%3Dd
3 http%3A%2F%2F%E4%BD%A0%E5%A5%BD
4 test

Encode with a custom encoding

Test data (T2)

id (INT) input (VARCHAR) encoding (VARCHAR)
1 http://你好 gb2312
2 http://test?a=b&c=d UNKNOWN

Test statement

SELECT
    id,
    URL_ENCODE(input, encoding) AS `value`
FROM
    T2;

Test result

id (INT) value (VARCHAR)
1 http%3A%2F%2F%C4%E3%BA%C3
2 NULL

Row 2 returns NULL because UNKNOWN is not a supported encoding format.

What's next