You are here:

Oracle/Making Data as Column Names for View

Advertisement


Question
Good day Sir!
How do I create a view where the columns are based on data in the table?Is that possible? For example I have an audit table:
a_logno varchar(10)
a_eventid varchar(10)
a_datetime date
a_userid varchar(10)

say the values for a_eventid are A, B, C
and i want to create a view that will look like this:
a_logno varchar(10)
A datetime
B datetime
C datetime
and the contents of columns A,B,C are the datetime corresponding to the events.
Is this possible Sir?
Would really appreciate your help. Thanks very much!

Answer
Good day Vee,

I apologize for the late reply.  It is currently a long weekend here in Canada and I just happened to check my email.

To answer your question, it looks like you want to transpose the row to column.  With Oracle, you can use the following

Here is an example to help you to do that
http://www.dba-oracle.com/t_converting_rows_columns.htm
http://www.oracle.com/technology/oramag/code/tips2004/050304.html

Tom Kyte also had a thread to talk about another way to do that
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:124812348063

Hope it helps.  Let me know you have difficulties in getting this works.

Cheers
Elliot

Oracle

All Answers


Answers by Expert:


Ask Experts

Volunteer


Elliot Mak

Expertise

I can answer questions with regarding to Oracle DB (8i, 9i, 10g, 11g) installation, configuration, administration, Data Guard, SQL, and PL/SQL (Procedures, triggers, functions).

Experience

I am an Oracle DBA, Senior PA, Project Manager, and Data Architect with 10 years of experience.

Education/Credentials
Bachelor of Science in Management System

©2012 About.com, a part of The New York Times Company. All rights reserved.