The UTL_HTTP system package is a system tool that enables HTTP and HTTPS communication in a PL/SQL environment. It allows the database to directly interact with external web services.
Note
The system package was introduced in OceanBase Database V4.4.1.
Overview of UTL_HTTP subprograms
The following table lists the UTL_HTTP subprograms supported in the current version of OceanBase Database and their brief descriptions.
| Subprogram | Description |
|---|---|
| BEGIN_REQUEST | Establishes an HTTP connection with the given URL, sends an HTTP request to the URL, and returns a req variable |
| END_REQUEST | Forcibly closes a request, regardless of whether the request or subsequent response is completed, and closes the HTTP connection |
| GET_RESPONSE | Retrieves the response to an HTTP request |
| END_RESPONSE | Terminates the response to an HTTP request after the request is completed |
| READ_LINE | Reads a line of text data from the HTTP response body |
| READ_RAW | Reads binary data from the HTTP response body |
| READ_TEXT | Reads text data |
| WRITE_LINE | Writes a line of text data to the HTTP request body |
| WRITE_RAW | Writes binary data to the HTTP request body |
| WRITE_TEXT | Writes text data to the HTTP request body |
| SET_TRANSFER_TIMEOUT | Sets the maximum timeout for HTTP data transfer |
| GET_TRANSFER_TIMEOUT | Retrieves the current maximum timeout for HTTP data transfer |
Examples
Send a GET request:
DECLARE
req UTL_HTTP.REQ;
resp UTL_HTTP.RESP;
url VARCHAR2(256) := 'https://api.example.com/data';
buf VARCHAR2(4000);
BEGIN
req := UTL_HTTP.BEGIN_REQUEST(url, 'GET');
resp := UTL_HTTP.GET_RESPONSE(req);
LOOP
UTL_HTTP.READ_TEXT(resp, buf);
DBMS_OUTPUT.PUT_LINE(buf);
END LOOP;
EXCEPTION
WHEN UTL_HTTP.END_OF_BODY THEN
UTL_HTTP.END_RESPONSE(resp);
END;