Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

flip columns into rows

Status
Not open for further replies.
Jun 15, 1999
18
US
I have a table (ABC) that has:
pro varchar2(12) not null (primary key)
pat varchar2(12) not null (primary key)
ic1 varchar2(1)
ic2 varchar2(1)
ic3 varchar2(1)
ic4 varchar2(1)

If I want to create a view that will return a row for each ic type i could specify:

create or replace view as
select pro,pat,ic1 as 'ictype',ic1 as 'icvalue'
union
select pro,pat,ic2 as 'ictype',ic2 as 'icvalue'
union
select pro,pat,ic3 as 'ictype',ic3 as 'icvalue'
union
select pro,pat,ic4 as 'ictype',ic4 as 'icvalue'
;

and this would return rows for each ic value. My question is, is there a more efficent way to do this via a view. With my example, worst case I am making 4 passes thru the data. Unfortunately I need to implement this via a view rather than a stored procedure since the product the programmers use doesn't support stored procedures (how neanderthal is that!)

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top