Home » SQL & PL/SQL » SQL & PL/SQL » How to print numbers side by side in a loop using dbms_output
How to print numbers side by side in a loop using dbms_output [message #211778] Tue, 02 January 2007 04:24 Go to next message
world.apps
Messages: 70
Registered: January 2007
Location: Hyderabad
Member
Hi,

I have been trying to get the solution for the fallowing code.

declare
i int;
n int:=4;
begin
i:=1;
loop
if(i<=n)
dbms_output.put_line(i);
end if;
end loop;
end;

For this i am getting output:
1
2
3
4

If we want to print it like this 1 2 3 4 in a single line. what have i to do?

Please if anyone knows this, send me a solution.

Thanks in Advance
Re: How to print numbers side by side in a loop using dbms_output [message #211781 is a reply to message #211778] Tue, 02 January 2007 04:34 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
As is so often the case, the answer is read the documentation. You need to use PUT rather than PUT_LIBE (which appends a cr to the text)
SQL> set serveroutput on
SQL> declare
  2  n int:=4;
  3  begin
  4  for i in 1..n loop
  5    dbms_output.put(i||' ');
  6  end loop;
  7  dbms_output.PUT_LINE('');
  8  end;
  9  /
1 2 3 4

PL/SQL procedure successfully completed.
Re: How to print numbers side by side in a loop using dbms_output [message #212006 is a reply to message #211781] Wed, 03 January 2007 08:07 Go to previous message
world.apps
Messages: 70
Registered: January 2007
Location: Hyderabad
Member
I got it thanks.

Could you tell me how to use interval datatype in oracle. I mean what value we have to give for this data type.

Thanks in advance

[Updated on: Wed, 03 January 2007 08:09]

Report message to a moderator

Previous Topic: Referential Integrity: How important?
Next Topic: Date Format
Goto Forum:
  


Current Time: Sun Dec 04 21:01:06 CST 2016

Total time taken to generate the page: 0.05824 seconds