Purpose
This function URL-encodes non-ASCII characters in a string to convert them into pure ASCII characters. It converts non-alphanumeric characters in expr into the format of % followed by two hexadecimal digits.
Considerations
- This function currently only supports the
utf8collation. - If the input is of the string type, the output collation remains consistent with the input. If the input is not of the string type, the output collation is the default collation of the current session.
Syntax statement
URL_ENCODE(expr)
Parameters
expr: The string to be URL-encoded.
Return type
- Returns a URL-encoded string of the
VARCHARtype. - If the value of
exprisNULL, returnNULL.
Examples
SELECT URL_ENCODE('https://example.com/path?name=John Doe&age=25'), URL_ENCODE(NULL);
The return result is as follows:
+-----------------------------------------------------------------+------------------+
| URL_ENCODE('https://example.com/path?name=John Doe&age=25') | URL_ENCODE(NULL) |
+-----------------------------------------------------------------+------------------+
| https%3A%2F%2Fexample.com%2Fpath%3Fname%3DJohn%20Doe%26age%3D25 | NULL |
+-----------------------------------------------------------------+------------------+
1 row in set