Inputting and Outputting Data with PL/SQL

Previous
Previous
Next
Next

Most PL/SQL input and output is through SQL statements, to store data in database tables or to query those tables. All other PL/SQL I/O is done through APIs that interact with other programs. For example, the DBMS_OUTPUT package has procedures such as PUT_LINE. To see the result outside of PL/SQL requires another program, such as the SQL Commands page or SQL Command Line (SQL*Plus), to read and display the data passed to DBMS_OUTPUT.

The SQL Commands page is configured to display output with DBMS_OUTPUT. SQL Command Line does not display DBMS_OUTPUT data unless you first issue the SQL*Plus command SET SERVEROUTPUT ON. For information about SQL Command Line SET command, see "SQL Command Line SET Commands" .

Example: Using DBMS_OUTPUT.PUT_LINE to Display PL/SQL Output show the use of DBMS_OUTPUT.PUTLINE. Note the use of SET SERVEROUTPUT ON to enable output.

Using DBMS_OUTPUT.PUT_LINE to Display PL/SQL Output

-- enable SERVEROUTPUT in SQL Command Line (SQL*Plus) to display output with 
-- DBMS_OUTPUT.PUT_LINE, this enables SERVEROUTPUT for this SQL*Plus session only
SET SERVEROUTPUT ON

DECLARE
  answer  VARCHAR2(20); -- declare a variable
BEGIN
-- assign a value to a variable
  answer := 'Maybe';
-- use PUT_LINE to display data from the PL/SQL block
  DBMS_OUTPUT.PUT_LINE( 'The answer is: ' || answer );
END;
/

The DBMS_OUTPUT package is a predefined Oracle package. For information about Oracle supplied packages, see "Oracle Provided Packages".


See Also: