Skip to main content
Version: V1.0.0

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 utf8 character 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 (VARCHAR type).
  • Returns NULL if expr is NULL.

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)

References

URL_DECODE