Updated on 2024-10-25 GMT+08:00

URL Function

Extraction Function

Description: Extracts content from an HTTP URL (or any URL that complies with the RFC 2396 standard).

[protocol:][//host[:port]][path][?query][#fragment]

The extracted content does not contain URI syntax separators, such as : or ?.

  • url_extract_fragment(url) → varchar

    Description: Returns the segment identifier of the URL, that is, the character string following #.

    select url_extract_fragment('http://www.example.com:80/stu/index.html?name=xxx&age=25#teacher');--teacher
  • url_extract_host(url)→ varchar

    Description: Returns the host domain name in url.

     select url_extract_host('http://www.example.com:80/stu/index.html?name=xxx&age=25#teacher');-- www.example.com
  • url_extract_parameter(url, name)→ varchar

    Description: Returns the name parameter in url.

    select url_extract_parameter('http://www.example.com:80/stu/index.html?name=xxx&age=25#teacher','age');-- 25
  • url_extract_path(url)→ varchar

    Description: Extracts the path from url.

     select url_extract_path('http://www.example.com:80/stu/index.html?name=xxx&age=25#teacher');-- /stu/index.html
  • url_extract_port(url)→ bigint

    Description: Extracts the port number from url.

    select url_extract_port('http://www.example.com:80/stu/index.html?name=xxx&age=25#teacher');-- 80
  • url_extract_protocol(url)→ varchar

    Description: Extracts the protocol from url.

    select url_extract_protocol('http://www.example.com:80/stu/index.html?name=xxx&age=25#teacher'); --  http
  • url_extract_query(url)→ varchar

    Description: Extracts the query character string from url.

    select url_extract_query('http://www.example.com:80/stu/index.html?name=xxx&age=25#teacher'); -- name=xxx&age=25 

Encoding Function

  • url_encode(value) → varchar

    Description: Escapes value so that it can be securely contained in the URL query parameter name and value.

    • Letter characters are not encoded.
    • Characters ., -, *, and _ are not encoded.
    • ASCII space characters are encoded as +.
    • All other characters are converted to UTF-8, and the byte is encoded as a string %XX, where XX is an uppercase hexadecimal value of UTF-8 bytes.
    select url_encode('http://www.example.com:80/stu/index.html?name=xxx&age=25#teacher');
    -- http%3A%2F%2Fwww.example.com%3A80%2Fstu%2Findex.html%3Fname%3Dxxx%26age%3D25%23teacher
  • url_decode(value) → varchar

    Description: Decodes the URL after value encoding.

    select url_decode('http%3A%2F%2Fwww.example.com%3A80%2Fstu%2Findex.html%3Fname%3Dxxx%26age%3D25%23teacher');
    -- http://www.example.com:80/stu/index.html?name=xxx&age=25#teacher