21

I'm just getting into PL/SQL, and I tried to run the following code, and I am getting anonymous block completed, but I think I should be getting Testing output. Does any know what I am doing wrong?

DECLARE
   message varchar2(20) := 'Testing output';
BEGIN
   dbms_output.put_line(message);
END;
/
1
  • 2
    The answer depends on what client you're using. SET SERVEROUTPUT ON is correct for SQL*Plus. Other tools have their own means for retrieving the results from dbms_output. Commented Feb 12, 2013 at 2:46

7 Answers 7

56

Viewing the DBMS_OUTPUT depends on the program.

SQL*Plus and Oracle SQL Developer

Run SET SERVEROUTPUT ON; first. This is all that's necessary in SQL*Plus or recent versions of Oracle SQL Developer.

SET SERVEROUTPUT ON;
begin
    dbms_output.put_line('Testing output');
end;
/

PL/SQL Developer

Output is automatically detected and displayed in the "Output" tab.

Sign up to request clarification or add additional context in comments.

5 Comments

thanks for the quick reply. I set serveroutput to on and it worked. Is there a way that i can run it in sqldeveloper though?
That's cool. Are you running from CLI? And yes, when I was using Oracle during my module I used sql developer through out.
In SQL Developer select "View" -> "DBMS Output".
Dbms Output is opened, it is connected to correct connection, but nothing is displayed
I'm trying it online with Oracle SQL worksheet and it's giving Unsupported Command error. Any idea how I could work it out?
8

Yes, in Oracle SQL Developer put the statement:

SET SERVEROUTPUT ON;

just before your DECLARE keyword and this should work.

I couldn't find View -> DBMS Output and I'm using version 1.5.5.

Comments

5

Yes. There is way to see output in SQL Developer.

Click ->View->Dbms Output and then click + symbol on Dbms output window. now you can run the procedure and can see output.

Comments

1

`The following statement will give the possible solution try this out

SET SERVEROUTPUT ON;

Then Run this code will get the following output

declare
a integer :=10;
b integer :=20;
c integer;
f real;
begin
c := a+b;
dbms_output.put_line('value of c: ' || c);
f := 70.0/3.0;
dbms_output.put_line('value of f: ' || f);

end; /

The code will give the following output

value of c: 30 value of f: 23.3333333333333333333333333333333333333

PL/SQL procedure successfully completed.

Comments

0

Yes, this is correct. You need to use before this block:

SET SERVEROUTPUT ON

Then, message get displayed on window.

Else we can check in SQL Developer select "View" -> "DBMS Output".
and in PLSQL developer under the OutPut tab we can check message.

2 Comments

Where do you put the set block? In the declaration?
Before the Declare works for me
-2

If you are getting "anonymous block completed" while executing the procedure by typing "EXECUTE ;" then run the below command & again execute the procedure. command is

SET SERVEROUTPUT ON;

1 Comment

This simply repeats the existing answers. As such what additional value do you think it has?
-2
**SET SERVEROUTPUT ON;**
DECLARE
   a INTEGER :=10;
   b INTEGER :=20;
   c float ;
   d real ;

BEGIN
   c :=a+b;
   dbms_output.put_line('the value of C is :'|| c);
   d := 70.0/3.3;
   dbms_output.put_line('the value of d is:'|| d);
END;

This will give you the output

the value of C is: 30
the value of d is: 21.21212121212121212121212121212121212121

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.