Connecting Tech Pros Worldwide Forums | Help | Site Map

query to convert column into rows in oracle9i

Newbie
 
Join Date: Nov 2007
Posts: 8
#1: Nov 30 '07
hi all

i am having a table in d form

COLNAME VALUE
NAME ABC
ROLLNO 2
ADDRESS DELHI
CLASS 12TH
NAME CDE
ROLLNO 3
ADDRESS PUNE
CLASS BSC
NAME EFG
ROLLNO 4
ADDRESS CHD
CLASS MCA

And i want d output in the following format by using some query in oracle 9i.

NAME ROLLNO ADDRESS CLASS
ABC 2 DELHI 12TH
CDE 3 PUNE BSC
EFG 4 CHD MCA


can sombody help me regarding ds?

thnx in advance
aman

debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 7,508
#2: Nov 30 '07

re: query to convert column into rows in oracle9i


Find realted topic a here and few others in the How To section of oracle.
Newbie
 
Join Date: Nov 2007
Posts: 8
#3: Nov 30 '07

re: query to convert column into rows in oracle9i


I Had Created The Table
As T1

Colname Value
Name Cde
Roll 3
Class Bsc
Address Pune
Name Efg
Roll 2
Class 12
Address Delhi
Name Abc
Roll 4
Class Mca
Address Chd


Now To Select D Data I Used D Query

Select (case When Colname ='name' Then Value End) As Name
,(case When Colname ='roll' Then Value End) Roll
,(case When Colname ='class' Then Value End) Class1
From T1
Order By Colname

It Gives Following Output

Name Roll Class1
' ' ' ' ' '
' ' ' ' ' '
' ' ' ' ' '
' ' ' ' Bsc
' ' ' ' Mca
' ' ' ' 12
Cde ' ' ' '
Abc ' ' ' '
Efg ' ' ' '
' ' 3 ' '
' ' 4 ' '
' ' 2 ' '

It Gives Gaps

But I Want In Following Format

Name Roll Class1
Cde 3 Bsc
Abc 4 Mca
Efg 2 12
QVeen72's Avatar
Moderator
 
Join Date: Oct 2006
Location: Bangalore
Posts: 1,385
#4: Dec 1 '07

re: query to convert column into rows in oracle9i


Hi,

There must be some ID for the Table,..

NAME ABC
ROLLNO 2
ADDRESS DELHI
CLASS 12TH

All the above 4 rows, should have Some Common Field Value..
What is the ID Column here....? This is Required for Pivoting ...

Regards
Veena
Newbie
 
Join Date: Nov 2007
Posts: 8
#5: Dec 3 '07

re: query to convert column into rows in oracle9i


No but there is no field like dt
Reply