Home » SQL & PL/SQL » SQL & PL/SQL » Read Column name in select query
Read Column name in select query [message #245643] Mon, 18 June 2007 04:58 Go to next message
newtooracle123
Messages: 24
Registered: May 2007
Junior Member
Hi,

I want the column name of in the select query.
For example.
If I have a emp table with emp_name , emp_id, salary column.
then I want to write a select query where in I can get something like this

select * from emp;

emp_name emp_id salary
---------------------------
xxx 111 1000
yyy 222 2000

And my requirement is something like this

emp_id column_name
-------------------------------------
111 emp_id
222 emp_id

Hope I am clear.
Can anyone help me please
Re: Read Column name in select query [message #245648 is a reply to message #245643] Mon, 18 June 2007 05:09 Go to previous messageGo to next message
Michel Cadot
Messages: 64152
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
The easiest answer is:
select emp_id, 'emp_id' column_name from emp.

but I think this is not you want.
You can write something like Tom Kyte's print_table function (can't currently access to AskTom so can't give you the link but just type "print_table" in the search field.

Regards
Michel
Re: Read Column name in select query [message #245651 is a reply to message #245648] Mon, 18 June 2007 05:16 Go to previous messageGo to next message
Michel Cadot
Messages: 64152
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Ok, found it: http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1035431863958

Regards
Michel
Re: Read Column name in select query [message #245652 is a reply to message #245651] Mon, 18 June 2007 05:30 Go to previous messageGo to next message
newtooracle123
Messages: 24
Registered: May 2007
Junior Member
Ya your right.
I want it to happen dynamically
Re: Read Column name in select query [message #246620 is a reply to message #245652] Thu, 21 June 2007 08:51 Go to previous messageGo to next message
hemu
Messages: 16
Registered: May 2007
Junior Member
try this may it helps you


select empno,(select column_name from user_tab_cols where column_id=1 and table_name='EMP') from emp;



hemu
Re: Read Column name in select query [message #246627 is a reply to message #246620] Thu, 21 June 2007 09:06 Go to previous message
Michel Cadot
Messages: 64152
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Does 1 more dynamic than 'EMPNO'?

Regards
Michel
Previous Topic: Using a procedure in a select clause
Next Topic: Reg : Comment (Drop)
Goto Forum:
  


Current Time: Sat Dec 10 08:51:52 CST 2016

Total time taken to generate the page: 0.12947 seconds