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;
/
APC
  • 144,005
  • 19
  • 170
  • 281
user1817081
  • 1,185
  • 3
  • 15
  • 21
  • 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`. – Jeffrey Kemp Feb 12 '13 at 02:46

7 Answers7

55

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.

Jon Heller
  • 34,999
  • 6
  • 74
  • 132
Lews Therin
  • 10,907
  • 4
  • 48
  • 72
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.

Giuseppe Garassino
  • 2,272
  • 1
  • 27
  • 47
Alvin Bunk
  • 7,621
  • 3
  • 29
  • 45
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.

MADHAIYAN M
  • 2,028
  • 25
  • 22
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.

Pronab Roy
  • 1,058
  • 1
  • 14
  • 18
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.

Eray Balkanli
  • 7,752
  • 11
  • 48
  • 82
user2001117
  • 3,727
  • 1
  • 18
  • 18
-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
Eray Balkanli
  • 7,752
  • 11
  • 48
  • 82
-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;

Bablu Gope
  • 21
  • 3