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!

How to select only the first column of a table

694243Mar 4 2010 — edited Mar 4 2010
Hello,

the system table USER_TAB_COLS gives us information about the columns of a table, including columns' internal id. I need a query to select a column from a table with a certain internal id, for example internal_column_id = 1.

So, if the query
select column_name
from user_tab_cols
where table_name = customers and internal_column_id = 1
returns "NAME", then I need the statement
select NAME from customers
Of course, I need some dynamic in the SQL, which means, that I don't know the column name when I write the second SQL statement. I need something like this:
select 
(
select column_name
from user_tab_cols
where table_name = customers and internal_column_id = 1
)
from customers
The inner select statement should return NAME and this column should be selected by the outer statement.

Do you have any ideas?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 1 2010
Added on Mar 4 2010
7 comments
5,530 views