Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

convert columns into rows using dynamic in clause

Marco FoxxFeb 15 2017 — edited Feb 15 2017

DB 11gR2

create table t (

  ID int,Attribute varchar2(1),Value int

);

insert into t values (1,'X',3);

insert into t values (2,'Y',4);

insert into t values (3,'X',5);

insert into t values (4,'X',6);

insert into t values (5,'Y',7);

insert into t values (6,'Z',8);

insert into t values (7,'A',9);

create table t1 (

  ID int,Attribute varchar2(1),Value int

);

insert into t values (1,'X',3);

insert into t values (2,'Y',4);

insert into t values (3,'X',5);

insert into t values (4,'X',6);

insert into t values (5,'Y',7);

insert into t values (6,'Z',8);

insert into t values (7,'A',9);

output :

i wanted display all values into rows wise record as of now i am getting it as clumne wise so i have used PPIVOT to do the same.

select * from (

   select ID, Attribute, Value

   from  t where id = 1

)

pivot

(

   sum(ID)

   for Attribute in (select Attribute from t1)  ---> this gives me Missing expression error if i use Static values it works something like ('X','Y')

)

Ref : sql - How to convert Columns into Rows in Oracle? - Stack Overflow

This post has been answered by Ahmed Haroon on Feb 15 2017
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 15 2017
Added on Feb 15 2017
19 comments
2,342 views