DBMS_OUTPUT Package
1. Purpose
DBMS_OUTPUT records debugging messages from anonymous blocks, stored procedures, and functions. The package stores messages in a session buffer for later retrieval.
2. Functionality
The ivorysql_ora extension provides DBMS_OUTPUT. Make sure the extension is installed in the current database. Connect with IvorySQL’s psql using the Oracle compatibility port, which defaults to 1521 and selects Oracle compatibility mode for the session.
psql -h localhost -p 1521 -d postgres
2.1. Interfaces
Call each procedure with the DBMS_OUTPUT. prefix.
| Procedure | Description |
|---|---|
|
Enables buffering. The default is 20,000 bytes, and values below 2,000 are treated as 2,000. Pass |
|
Disables buffering and clears the buffer. Writes while disabled are ignored. |
|
Appends text to the current line without ending it. |
|
Appends text and ends the current line. |
|
Ends the current line. If there is no pending text, it adds an empty line. |
|
Retrieves one line. A status of 0 means a line was read, and 1 means no line was available. The |
|
Retrieves lines in a batch. Pass the requested count in |
2.2. Usage Notes
-
Call
ENABLEbefore writing. UseNEW_LINEorPUT_LINEto complete a line started withPUTbefore reading it. -
In IvorySQL’s
psql, a top-levelCALLtoGET_LINEorGET_LINESdisplays the output parameters as result columns.psqldoes not support SQL*Plus’sSET SERVEROUTPUT ON. -
In a PL/iSQL block, read the output into local variables. You can print the retrieved text with
RAISE NOTICE. -
Use the same database connection to write and read. Reading removes the retrieved lines. The buffer survives commits and rollbacks.
-
Repeating
ENABLEupdates the capacity limit and preserves unread lines and unfinishedPUTtext. CallDISABLEfollowed byENABLEto start with an empty buffer.DISCARD ALL,DISCARD PACKAGE, and disconnecting also clear the buffer.DISCARD PACKAGEis available in Oracle compatibility mode. -
Each line can contain up to 32,767 bytes. Exceeding the line limit raises
ORU-10028. Exceeding the buffer limit raisesORU-10027. Shorten lines, read them sooner, or adjust the buffer capacity as appropriate.
3. Examples
Run these examples in IvorySQL’s psql.
3.1. Write and Read One Line
CALL DBMS_OUTPUT.ENABLE();
CALL DBMS_OUTPUT.PUT_LINE('Hello, IvorySQL!');
CALL DBMS_OUTPUT.GET_LINE(NULL, NULL);
The two NULL arguments are placeholders for the OUT parameters.
line | status ------------------+-------- Hello, IvorySQL! | 0 (1 row)
3.2. Assemble Text and Read a Batch
CALL DBMS_OUTPUT.ENABLE(NULL);
CALL DBMS_OUTPUT.PUT('Task: ');
CALL DBMS_OUTPUT.PUT('demo');
CALL DBMS_OUTPUT.NEW_LINE();
CALL DBMS_OUTPUT.PUT_LINE('Finished');
CALL DBMS_OUTPUT.GET_LINES(NULL::text[], 10);
NULL::text[] selects the TEXT[] overload. This call requests up to 10 lines and returns two. Call GET_LINES again with the desired batch size if more lines remain.
lines | numlines
-------------------------+----------
{"Task: demo",Finished} | 2
(1 row)