URL_ENCODE
Description
This function is used to encode non-ASCII characters in a string into 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
utf8character set. - If the input is a string, the output collation remains consistent with the input. If the input is not a string, the output collation will use the default collation of the current session.
Syntax
URL_ENCODE(expr)
Parameters
expr: The string to be URL-encoded.
Return Type
- Returns a URL-encoded string (
VARCHARtype). - Returns
NULLifexprisNULL.
Examples
SELECT URL_ENCODE('https://example.com/path?name=John Doe&age=25'), URL_ENCODE(NULL);
The 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 (0.001 sec)