DBMS_OUTPUT v12
The DBMS_OUTPUT
package provides the capability to send messages (lines of text) to a message buffer, or get messages from the message buffer. A message buffer is local to a single session. Use the DBMS_PIPE
package to send messages between sessions.
The procedures and functions available in the DBMS_OUTPUT
package are listed in the following table.
Function/Procedure | Return Type | Description |
---|---|---|
DISABLE | n/a | Disable the capability to send and receive messages. |
ENABLE(buffer_size) | n/a | Enable the capability to send and receive messages. |
GET_LINE(line OUT, status OUT) | n/a | Get a line from the message buffer. |
GET_LINES(lines OUT, numlines IN OUT) | n/a | Get multiple lines from the message buffer. |
NEW_LINE | n/a | Puts an end-of-line character sequence. |
PUT(item) | n/a | Puts a partial line without an end-of-line character sequence. |
PUT_LINE(item) | n/a | Puts a complete line with an end-of-line character sequence. |
SERVEROUTPUT(stdout) | n/a | Direct messages from PUT, PUT_LINE, or NEW_LINE to either standard output or the message buffer. |
The following table lists the public variables available in the DBMS_OUTPUT
package.
Public Variables | Data Type | Value | Description |
---|---|---|---|
chararr | TABLE | For message lines. |
CHARARR
The CHARARR
is for storing multiple message lines.
DISABLE
The DISABLE
procedure clears out the message buffer. Any messages in the buffer at the time the DISABLE
procedure is executed will no longer be accessible. Any messages subsequently sent with the PUT, PUT_LINE,
or NEW_LINE
procedures are discarded. No error is returned to the sender when the PUT, PUT_LINE,
or NEW_LINE
procedures are executed and messages have been disabled.
Use the ENABLE
procedure or SERVEROUTPUT(TRUE)
procedure to re-enable the sending and receiving of messages.
Examples
This anonymous block disables the sending and receiving messages in the current session.
ENABLE
The ENABLE
procedure enables the capability to send messages to the message buffer or retrieve messages from the message buffer. Running SERVEROUTPUT(TRUE)
also implicitly performs the ENABLE
procedure.
The destination of a message sent with PUT, PUT_LINE,
or NEW_LINE
depends upon the state of SERVEROUTPUT
.
- If the last state of
SERVEROUTPUT
isTRUE
, the message goes to standard output of the command line. - If the last state of
SERVEROUTPUT
isFALSE
, the message goes to the message buffer.
Parameter
buffer_size
Maximum length of the message buffer in bytes. If a buffer_size
of less than 2000 is specified, the buffer size is set to 2000.
Examples
The following anonymous block enables messages. Setting SERVEROUTPUT(TRUE)
forces them to standard output.
The same effect could have been achieved by simply using SERVEROUTPUT(TRUE)
.
The following anonymous block enables messages, but setting SERVEROUTPUT(FALSE)
directs messages to the message buffer.
GET_LINE
The GET_LINE
procedure provides the capability to retrieve a line of text from the message buffer. Only text that has been terminated by an end-of-line character sequence is retrieved – that is complete lines generated using PUT_LINE
, or by a series of PUT
calls followed by a NEW_LINE
call.
Parameters
line
Variable receiving the line of text from the message buffer.
status
0 if a line was returned from the message buffer, 1 if there was no line to return.
Examples
The following anonymous block writes the emp
table out to the message buffer as a comma-delimited string for each row.
The following anonymous block reads the message buffer and inserts the messages written by the prior example into a table named messages
. The rows in messages
are then displayed.