Chapter 62. UTL_URL

Table of Contents

62.1. Overview
62.2. Functions
62.2.1. ESCAPE
62.2.2. UNESCAPE

This chapter briefly introduces the UTL_URL package, and describes how to use the functions of the package.

62.1. Overview

UTL_URL provides functions to encode a URL address to an escaped format. ESCAPE is used to convert illegal characters to %xx, the hexadecimal character representation in ASCII. Reserved characters can also be escaped to allow them to be treated as literals.

Character TypeRegular Expression
Unreserved characters[0-9] | [a-zA-Z] | - | _ | . | ! | ~ |* | ` | ( | )
Reserved characters; | / | ? | ; | @ | & | = | + | $ | ,

62.2. Functions

This section describes the functions provided by the UTL_URL package, in alphabetical order.

62.2.1. ESCAPE

Converts a URL address to an escaped format.

Details about the ESCAPE function are as follows:

  • Prototype

    FUNCTION ESCAPE
    (
        url                     IN  VARCHAR2,
        escape_reserved_chars   IN  BOOLEAN  DEFAULT FALSE,
        url_charset             IN  VARCHAR2 DEFAULT utl_http.get_body_charset 
    ) 
    RETURN VARCHAR2;
  • Parameter

    ParameterDescription
    urlURL to escape.
    escape_reserved_chars

    Option to convert reserved characters to an escaped format.

    • TRUE: Reserved characters are converted.

    • FALSE: Reserved characters are not converted. (Default value)

    url_charset

    Character set of the URL address.

    The default character set of the UTL_HTTP package is used by default. The default character set of the HTTP message body is 'ISO-8859-1'.

  • Example

    BEGIN
      dbms_output.put_line( UTL_URL.ESCAPE('http://www.w3.org/blah blah.html') );
    END;
    /

62.2.2. UNESCAPE

Converts a URL address containing escaped (%xx) characters to a standard string.

Details about the UNESCAPE function are as follows:

  • Prototype

    FUNCTION UNESCAPE
    (
        url            IN  VARCHAR2,
        url_charset    IN  VARCHAR2 DEFAULT utl_http.get_body_charset 
    ) 
    RETURN VARCHAR2;
  • Parameter

    ParameterDescription
    urlURL to unescape.
    url_charset

    Character set of the URL.

    The default character set of the UTL_HTTP package is used by default. The default character set of the HTTP message body is 'ISO-8859-1'.

  • Exception

    ExceptionDescription
    URL_BAD_URLOccurs if an invalid escaped string is encountered.
  • Example

    DECLARE
        ourl VARCHAR2(32767);    
        eurl VARCHAR2(32767);    
    BEGIN
        eurl := UTL_URL.ESCAPE('http://www.w3.org/Protocols/');
        ourl := UTL_URL.UNESCAPE(eurl);
    END;
    /