Oracle SQL - Selecting column without knowing column name Oracle SQL - Selecting column without knowing column name oracle oracle

Oracle SQL - Selecting column without knowing column name


Is it possible? Sure. You could write a PL/SQL block that used dbms_sql to open a cursor using the actual query against dual, describe the results, bind a variable to whatever you find the second column to be, fetch from the cursor, and then loop. That would be a terribly involved and generally rather painful process but it could be done.

The SQL language does not define a way to do this in a static SQL statement and Oracle does not provide an extension that would allow this. I'd be rather concerned about the underlying problem that you're trying to solve, though, if you somehow know that you want the second column but don't know what that column represents. That's not something that makes a lot of sense in a relational database.


SELECT ORDINAL_POSITION, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNSWHERE TABLE_NAME = 'dual'

not sure if this is what you need.


If you don't know the name, just give it a nice name ;).

Select b FROM (    Select 'a', 'b' as b, 'c', 'd' from dual)