Oracle8i Supplied PL/SQL Packages Reference Release 2 (8.1.6) Part Number A76936-01 |
|
UTL_HTTP , 2 of 2
This function returns up to the first 2000 bytes of data retrieved from the given URL.
UTL_HTTP.REQUEST ( url IN VARCHAR2, proxy IN VARCHAR2 DEFAULT NULL) wallet_path wallet_password RETURN VARCHAR2;
pragma restrict_references (request, wnds, rnds, wnps, rnps);
Table 61-3 shows the parameters for the REQUEST function.
Its return-type is a string of length 2000 or less, which contains up to the first 2000 bytes of the HTML result returned from the HTTP request to the argument URL.
INIT_FAILED
REQUEST_FAILED
SQLPLUS> SELECT utl_http.request('http://www.oracle.com/') FROM dual; UTL_HTTP.REQUEST('HTTP://WWW.ORACLE.COM/') <html> <head><title>Oracle Corporation Home Page</title> <!--changed Jan. 16, 19 1 row selected.
If you are behind a firewall, include the proxy
parameter. For example, from within the Oracle firewall, where there might be a proxy server named www-proxy
.us
.oracle
.com
:
SQLPLUS> SELECT utl_http.request('http://www.oracle.com', 'www-proxy.us.oracle.com') FROM dual;
This function returns a PL/SQL table of 2000-byte pieces of the data retrieved from the given URL.
type html_pieces is table of varchar2(2000) index by binary_integer; UTL_HTTP.REQUEST_PIECES ( url IN VARCHAR2, max_pieces NATURAL DEFAULT 32767, proxy IN VARCHAR2 DEFAULT NULL) wallet_path wallet_password RETURN HTML_PIECES;
pragma restrict_references (request_pieces, wnds, rnds, wnps, rnps);
Table 61-4 shows the parameters for the REQUEST function.
REQUEST_PIECES
returns a PL/SQL table of type UTL_HTTP
.HTML_PIECES
. Each element of that PL/SQL table is a string of length 2000. The final element may be shorter than 2000 characters.
The elements of the PL/SQL table returned by REQUEST_PIECES
are successive pieces of the data obtained from the HTTP request to that URL.
INIT_FAILED
REQUEST_FAILED
A call to REQUEST_PIECES
could look like the example below. Note the use of the PL/SQL table method COUNT
to discover the number of pieces returned, which may be zero or more:
DECLARE pieces utl_http.html_pieces; BEGIN pieces := utl_http.request_pieces('http://www.oracle.com/'); FOR i in 1 .. pieces.count loop .... -- process each piece END LOOP; END;
The following block retrieves up to 100 pieces of data (each 2000 bytes, except perhaps the last) from the URL. It prints the number of pieces retrieved and the total length, in bytes, of the data retrieved.
SET SERVEROUTPUT ON / DECLARE x utl_http.html_pieces; BEGIN x := utl_http.request_pieces('http://www.oracle.com/', 100); dbms_output.put_line(x.count || ' pieces were retrieved.'); dbms_output.put_line('with total length '); IF x.count < 1 THEN dbms_output.put_line('0'); ELSE dbms_output.put_line ((2000 * (x.count - 1)) + length(x(x.count))); END IF; END; / -- Output Statement processed. 4 pieces were retrieved. with total length 7687
|
![]() Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
|