Hi guys,

I have a number of tables where they have a column called "????_UNIT". I am trying to build a dinamyc SELECT to return the value of that column.

I am trying something like:

SELECT COLUMNNAME(
SELECT COLUMN_NAME
FROM ALL_TAB_COLUMNS
WHERE OWNER = 'MY-SCHEME' AND COLUMN_NAME LIKE '%UNIT' AND TABLE_NAME = 'MY-TABLE'
)
FROM MY-SCHEME.MY-TABLE
WHERE REF_CODE = 'SOMETHING'

I am building an internal SELECT to retrieve the column name for a table, and I would like to use it as the column name for the external SELECT. The only thing I get is the column name (????_UNIT).

Is there anything similar to "COLUMNNAME" I could use? Any tips?

Many thanks for your replies.


(PS: "COLUMNNAME" is invented)