Table of Contents

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

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