Encodes an input string in the application/x-www-form-urlencoded MIME
format and returns the encoded string.
Syntax
string url_encode(string <input>[, string <encoding>])
Description
Encodes an input string in the application/x-www-form-urlencoded MIME
format. The encoding format must comply with the following rules:
All letters remain unchanged.
Periods (.), hyphens (-), asterisks (*), and underscores (_) remain unchanged.
Spaces are converted into plus signs (+).
Other characters are converted into byte values based on the specified encoding format. Each byte value is then represented in the
%xy
format, wherexy
is the hexadecimal representation of the character value.
Parameters
input: required. A value of the STRING type. This parameter specifies the string that you want to enter.
encoding: optional. This parameter specifies the encoding format, which can be GBK or UTF-8. If you do not specify this parameter, the default value UTF-8 is used.
Return value
A value of the STRING type is returned. If the value of input or encoding is null, null is returned.
Examples
-- The return value is %E7%A4%BA%E4%BE%8Bfor+url_encode%3A%2F%2F+%28fdsf%29.
select url_encode('Example for url_encode:// (fdsf)');
-- The return value is 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 more information about functions related to string searches and conversion, see String functions.