Home » SQL & PL/SQL » SQL & PL/SQL » Formatting Output into multiple columns (Oracle 11g Express, Windows 8)
Formatting Output into multiple columns [message #582302] Tue, 16 April 2013 14:31 Go to next message
Kimberlicious
Messages: 10
Registered: April 2013
Junior Member
Hey guys, as part of an exercise we are to demonstrate a FOR LOOP from 1 - 100.

We must show the output as evidence of doing the work,

Is it possible to display the results in two columns, instead of all in one row? Because 100 rows will not fit it one screenshot! Thanks:)


BEGIN
	FOR i in 1..100
	LOOP
	    DBMS_OUTPUT.put_line(i);
	END LOOP;
END;
/

Re: Formatting Output into multiple columns [message #582303 is a reply to message #582302] Tue, 16 April 2013 14:32 Go to previous messageGo to next message
Michel Cadot
Messages: 57612
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Yes, there are other procedure in dbms_output package.
Just read the documentation and/or execute "desc dbms_output".

Regards
Michel
Re: Formatting Output into multiple columns [message #582304 is a reply to message #582302] Tue, 16 April 2013 14:35 Go to previous messageGo to next message
pointers
Messages: 336
Registered: May 2008
Senior Member
Try dbms_output.put, do it twice if the count is 2 then insert a new line
Re: Formatting Output into multiple columns [message #582306 is a reply to message #582304] Tue, 16 April 2013 15:19 Go to previous messageGo to next message
Kimberlicious
Messages: 10
Registered: April 2013
Junior Member
pointers wrote on Tue, 16 April 2013 14:35
Try dbms_output.put, do it twice if the count is 2 then insert a new line


Thanks but I am not sure what you mean by if the count is two?

I am looking for output like this in five columns:

http://farm9.staticflickr.com/8121/8656381622_1a12232403.jpg


I have tried this without success:

BEGIN
	FOR i in 1..100
	LOOP
	    dbms_output.put(i);
            dbms_output.new_line;
	    dbms_output.put(i);
            dbms_output.new_line;
	    dbms_output.put(i);
            dbms_output.new_line;
	    dbms_output.put(i);
            dbms_output.new_line;
	    dbms_output.put(i);
            	                	
	END LOOP;
END;
/

[Updated on: Tue, 16 April 2013 15:20]

Report message to a moderator

Re: Formatting Output into multiple columns [message #582311 is a reply to message #582306] Wed, 17 April 2013 00:29 Go to previous messageGo to next message
Michel Cadot
Messages: 57612
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Just think a little bit.
If you want to print 2 elements per line, you execute twice PUT and once NEW_LINE.
If you want to print 3 elements per line, you execute 3 times PUT and once NEW_LINE.
If you want to print 4 elements per line, you execute 4 times PUT and once NEW_LINE.
And so on.

But, of course, no one really uses this in real life as no one should use DBMS_OUTPUT but for debugging purpose.

Regards
Michel

Re: Formatting Output into multiple columns [message #582363 is a reply to message #582306] Wed, 17 April 2013 08:15 Go to previous message
joy_division
Messages: 4454
Registered: February 2005
Location: East Coast USA
Senior Member
Kimberlicious wrote on Tue, 16 April 2013 16:19
pointers wrote on Tue, 16 April 2013 14:35
Try dbms_output.put, do it twice if the count is 2 then insert a new line


Thanks but I am not sure what you mean by if the count is two?

I am looking for output like this in five columns:


Maybe because you asked for two?

Kimberlicious

Is it possible to display the results in two columns, instead of all in one row?
Previous Topic: Help with a select statement
Next Topic: print a message
Goto Forum:
  


Current Time: Sun Apr 20 00:25:03 CDT 2014

Total time taken to generate the page: 0.09702 seconds