Rudimentary issue: basic PL/SQL console output?

77,145

Since you are using SQL Developer, you have a couple of options.

In SQL Developer, go to View | DBMS Output to ensure that the DBMS Output window is visible. In the DBMS Output window, choose the "plus" icon and select the connection that you want to write data to the DBMS Output window. Then run the PL/SQL block in the SQL Worksheet window using the right arrow (Ctrl+Enter in Windows). You'll see the output appear in the DBMS Output window.

Alternately, you can put both the SQL*Plus SET SERVEROUTPUT ON command and the PL/SQL block in the SQL Worksheet and run it as a script (F5 in Windows). That will display the output immediately below the "anonymous block completed" message in the Script Output window.

Note: Dbms Output in Oracle Sql Developer doesn't show null in the output window. It moves to a new line, but until it will return something else than null, you'll not know all the previous nulls are there.

Share:
77,145

Related videos on Youtube

Justin Cave
Author by

Justin Cave

Oracle ACE Alumni

Updated on July 05, 2022

Comments

  • Justin Cave
    Justin Cave almost 2 years

    I am using SQL Developer and want to output the contents of a variable to the console using DBMS_OUTPUT.PUT_LINE(). I am running the following code that adds the numbers 1 through 5 inclusive but I'm not seeing any output.

    SET SERVEROUTPUT ON;
    DECLARE 
    n_counter NUMBER := 5; -- Substitute this variable
    n_sum     NUMBER := 0;
    BEGIN
      WHILE n_counter != 0
      LOOP
        n_sum := n_sum + n_counter;
        n_counter := n_counter -1;
      END LOOP;
      DBMS_OUTPUT.PUT_LINE(n_sum);
    END;
    

    Additionally, do you Know of better resources for troubleshooting issues than the incredibly dense Oracle PL/SQL documentation? [similar to Java SE7 API?]

    • Marc
      Marc about 12 years
      Do you reach the end of this routine? I.e. it's not an endless loop somehow, right? Doesn't appear to be.
    • Admin
      Admin about 12 years
      Yeah, the routine completes successfully.
    • Himanshu
      Himanshu over 5 years
      Can try with basic Loop instead of while because there seems to be no problem as such to get the output because ServerOutput is ON the only reason might be due to While Loop
  • Admin
    Admin about 12 years
    I'm using SQL Developer, and receive the following notification: Anonymous block completed. The goal is to add the values 1-5 inclusive.
  • Justin Cave
    Justin Cave about 12 years
    @TylerJFisher - Updated my answer
  • Zeus
    Zeus over 9 years
    Does this work only when debugging? currently my debbuger does not work, i'm still trying to run pl/sql by callign it from a sql file
  • Justin Cave
    Justin Cave over 9 years
    @Zeus - dbms_output is separate from the debugger. The debugger lets you actually step through code as it executes. dbms_output is much more primitive and just lets you write code to output bits of information.
  • Zeus
    Zeus over 9 years
    Thanks for answering. What is the best way to run a function in a package and let it print in the dbms output? also could you please take a look at the question stackoverflow.com/questions/28222952/… here