Oracle

 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Tutorialized ForumsDatabasesOracle

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old March 25th, 2009, 11:39 AM
ksuchetan ksuchetan is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Mar 2009
Posts: 1 ksuchetan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 25 sec
Reputation Power: 0
Vertical Pivot

Frankly telling this is an urgent requirement for me can you. Please help me.

There are two tables
1)T
2)T12

/************************************************** *********************

SQL> Create Table T
2 (Name varchar(9))
3 /

Table created.

SQL> Create Table T12
2 (P1 varchar(9),
3 P2 varchar(9),
4 P3 varchar(9))
5 /

Table created.


SQL> Insert into t values ('AA')
2 /

1 row created.

SQL> Insert into t values ('BB');

1 row created.

SQL> Insert into t values ('CC');

1 row created.

SQL> SELECT * FROM T


NAME
---------
AA
BB
CC

3 ROWS SELECTED

/************************************************** ************************************************/

The SQL query :

INSERT INTO TABLE12 values (p1,p2,p3)
SELECT MAX(CASE WHEN ROWNUM = 1
THEN NAME END) AS P1,
MAX(CASE WHEN ROWNUM = 2
THEN NAME END) AS P2,
MAX(CASE WHEN ROWNUM = 3
THEN NAME END) AS P3
from T


The desired o\p is

P1 P2 P3
AA BB CC

As I have about 128 rows in the table T and it is very tedious to write sql for this requirement.

I have written a very simple stored proc to do this:

/************************************************** **********
CREATE OR REPLACE PROCEDURE LOAD_DATA_BUCKET(v_tbl_nm in varchar2, v_db_schema varchar2) AS

BEGIN
declare
i number := 1;

begin
While i < 4 LOOP

execute immediate 'INSERT INTO TABLE T12(P'||i||'
)SELECT MAX(CASE WHEN ROWNUM = '||i||' THEN NAME
END) AS P'||i||' FROM Table T

i := i+1;
END LOOP;
commit;
end;

END;
/

/************************************************** ****************
O\p of this stored proc is :

P1 P2 P3
AA Null Null
Null BB Null
Null Null CC

The values were placed in three different rows.


Where as the desired output is


P1 P2 P3
AA BB CC


Please help

Thanks In Advance

Reply With Quote
Reply

Viewing: Tutorialized ForumsDatabasesOracle > Vertical Pivot


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap