Home » Other » Training & Certification » If I use Put_Line Then program get's compiled but o/p is not shown.
If I use Put_Line Then program get's compiled but o/p is not shown. [message #289829] Wed, 26 December 2007 04:21 Go to next message
balajiags
Messages: 10
Registered: July 2007
Junior Member
If I use Put_Line Then program get's compiled but o/p is not shown.

declare
begin
    dbms_output.put_line('Loops Starts here....');
for i in 1..9 loop
       dbms_output.put(lpad(i,4,' '));
end loop;
end;


If I change the program then o/p is visible.why?
declare
begin
    dbms_output.put_line('Loops Starts here....');
for i in 1..9 loop
       dbms_output.put(lpad(i,4,' '));
end loop;
   dbms_output.put_line(' ');
end;
Re: If I use Put_Line Then program get's compiled but o/p is not shown. [message #289838 is a reply to message #289829] Wed, 26 December 2007 04:38 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Because you SET SERVEROUTPUT ON between executing those PL/SQL blocks.
SQL> -- no output, whichever PL/SQL block you execute:
SQL> declare
  2  begin
  3      dbms_output.put_line('Loops Starts here....');
  4  for i in 1..9 loop
  5         dbms_output.put(lpad(i,4,' '));
  6  end loop;
  7  end;
  8  /

PL/SQL procedure successfully completed.

SQL> declare
  2  begin
  3      dbms_output.put_line('Loops Starts here....');
  4  for i in 1..9 loop
  5         dbms_output.put(lpad(i,4,' '));
  6  end loop;
  7     dbms_output.put_line(' ');
  8  end;
  9  /

PL/SQL procedure successfully completed.
Now, enable the output:
SQL> set serveroutput on
SQL> -- the first PL/SQL block again:
SQL> declare
  2  begin
  3      dbms_output.put_line('Loops Starts here....');
  4  for i in 1..9 loop
  5         dbms_output.put(lpad(i,4,' '));
  6  end loop;
  7  end;
  8  /
Loops Starts here....

PL/SQL procedure successfully completed.

By the way, did you use DBMS_OUTPUT.PUT on purpose?
SQL> l5
  5*        dbms_output.put(lpad(i,4,' '));
SQL> c/.put/.put_line/
  5*        dbms_output.put_line(lpad(i,4,' '));
SQL> /
Loops Starts here....
1
2
3
4
5
6
7
8
9

PL/SQL procedure successfully completed.

SQL>
Re: If I use Put_Line Then program get's compiled but o/p is not shown. [message #290048 is a reply to message #289829] Thu, 27 December 2007 04:30 Go to previous message
Frank
Messages: 7901
Registered: March 2000
Senior Member
dbms_output.put holds the buffer until you flush it.
Previous Topic: month and month number
Next Topic: Can any one solve this
Goto Forum:
  


Current Time: Thu Apr 25 01:46:23 CDT 2024