Home » SQL & PL/SQL » SQL & PL/SQL » Dynamic Column Generation (Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production)
Dynamic Column Generation [message #609241] Tue, 04 March 2014 06:05 Go to next message
saipradyumn
Messages: 419
Registered: October 2011
Location: Hyderabad
Senior Member

Hi

Is there way to generate the following out put by using single query

Out Put  
------------------------------------------
C1    C2    C3    C4    C5    C6   C7     C8
 
*     *     *     *     *     *     *     *     

*     *     *     *     *     *     *     

*     *     *     *     *     *     

*     *     *     *     *     

*     *     *     *     

*     *     *     

*     *     

*



In put should be any number
We can get the rows by using Connect be level.But how to generate the required columns based on the input?


Thanks
Sai Pradyumn

Re: Dynamic Column Generation [message #609243 is a reply to message #609241] Tue, 04 March 2014 06:36 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

You can follow the way mentioned in Puzzle n°08 - Display the Numerical Pyramid using straight SQL query

Re: Dynamic Column Generation [message #609244 is a reply to message #609243] Tue, 04 March 2014 07:04 Go to previous messageGo to next message
saipradyumn
Messages: 419
Registered: October 2011
Location: Hyderabad
Senior Member

Hi Michel

Thank you very for your help. But there also we had hard coded the columns up to J.

My requirement was,need to generate the columns which equals to given in put

Ex : I am able to generate that many rows by the following query

 

SQL> select  '*' str from dual connect by level <= 5  ;
 
STR
--------------------------------
*
*
*
*
*



Like this is there any way to generate the columns for thr given in put ?

if the In put = 6 then Output should be like this

--------------
Str_1   Str_2   Str_3   Str_4   Str_5   Str_6   

*         *       *      *       *       * 



Thanks






Re: Dynamic Column Generation [message #609245 is a reply to message #609244] Tue, 04 March 2014 07:40 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
Thank you very for your help. But there also we had hard coded the columns up to J.


Not if you use the second method I posted which ends with:

Quote:
Then we are no more limited in the number of columns.


Re: Dynamic Column Generation [message #609248 is a reply to message #609241] Tue, 04 March 2014 09:21 Go to previous message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
Do you need just desired shape output or you need to generate it as set of separate columns? Michel's link shows how to generate that shape as a single column.

SY.
Previous Topic: Columns values into rows
Next Topic: cursor_sharing force 11g r2
Goto Forum:
  


Current Time: Fri Apr 26 01:11:30 CDT 2024