Quick Search:
 
 The Oracle PL/SQL UTL_URL Package      [Return To Index] Jump to:  

Term: UTL_URL

Definition:
In Oracle PL/SQL, UTL_URL is a built in utility package which is capable of escaping and unescaping (reading) the characters used in formatted URLs. A URL contains set of reserved and unreserved characters. The reserved characters are the delimiters or separators in the URL string. They are semi-colon (;) slash (/), question mark (?), colon (:), at sign (@), ampersand (&), equals sign (=), plus sign (+), dollar sign ($), and comma (,). The unreserved character set includes the alphabetic characters, numeric digits, and the remaining punctuation characters.

For a URL to be parsed properly, reserved characters must be escaped to read the URL string. The UTL_URL package provides two subprograms, ESCAPE() and UNESCAPE() to perform these operations.

1. ESCAPE function - Reads and escapes the reserved characters from the URL and returns their hex code in %2-digit-hex-code format. For example, a space character is rendered as "%20".

Example Syntax:

UTL_URL.ESCAPE (url IN VARCHAR2, 
escape_reserved_chars IN BOOLEAN DEFAULT FALSE,
url_charset IN VARCHAR2 DEFAULT utl_http.body_charset)
RETURN VARCHAR2;


2. UNESCAPE function - Unescapes the reserved characters (in %xx format) from the URL to their original format.

Example Syntax:

UTL_URL.UNESCAPE ( url IN VARCHAR2, 
url_charset IN VARCHAR2 DEFAULT utl_http.body_charset)
RETURN VARCHAR2;


UTL_URL exceptions

The possible exceptions which can be raised with UTL_URL are BAD_URL and BAD_FIXED_WIDTH_CHARSET.
The BAD_URL exception is raised due to a bad URL format (an improperly formed URL).
The BAD_FIXED_WIDTH_CHARSET exception is raised if the URL contains fixed width multipbyte characters.

Example Usage:

The SQL below demonstrates the use of the ESCAPE and UNESCAPE subprograms. The space character between "About" and "PSOUG" will be transformed.

SQL> SELECT utl_url.escape('http://psoug.org/About PSOUG') FROM dual
2 /

UTL_URL.ESCAPE(http://psoug.org/About PSOUG')
--------------------------------------------------------------------------------
http://psoug.org/About%20PSOUG


SQL> SELECT utl_url.unescape('http://psoug.org/About%20PSOUG') FROM DUAL
2 /

UTL_URL.UNESCAPE('http://psoug.org/About%20PSOUG/')
--------------------------------------------------------------------------------
http://psoug.org/About PSOUG

 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org