SQL Plus - Serveroutput system variable (Enabling DBMS_OUTPUT.PUT_LINE)

Card Puncher Data Processing

About

serveroutput is a system variable.

This variable controls whether to display output (that is, DBMS_OUTPUT.PUT_LINE) of stored procedures or PL/SQL blocks in SQL*Plus.

Resources are not pre-allocated when SERVEROUTPUT is set.

Example

SET SERVEROUTPUT ON
BEGIN
DBMS_OUTPUT.PUT_LINE ('hello');
END;
hello

Side Effect

Last Query is no more what you expect

When enabled, serveroutput will add this extra statement after your query:

BEGIN DBMS_OUTPUT.GET_LINES(:LINES, :NUMLINES); END;

It means that the last session query will always be this one. You can check it with this query

SELECT
  sql_text
FROM
  v$sql
WHERE
  sql_id =
  (
    SELECT
      prev_sql_id
    FROM
      V$session
    WHERE
      sid = SYS_CONTEXT( 'USERENV', 'SID' )
  );

Documentation / Reference





Discover More
Card Puncher Data Processing
Oracle Database - Explain Plan from Cursor Cache (DBMS_XPLAN.DISPLAY_CURSOR)

This DBMS_XPLAN.DISPLAY_CURSOR function display the execution plan of an already executed statement where the resulting cursor...
Card Puncher Data Processing
PL/SQL - DBMS_OUTPUT

View > DBMS_OUTPUT > +



Share this page:
Follow us:
Task Runner