Can we use Primary Keys as “normal columns” in Oracle?
I am trying to do the following query but it doesn’t work:
SELECT DATA_1,DATA_2 FROM MY_TABLE WHERE MY_TABLE_PK=10;
I have an Invalid identifier error:
SQL Error: ORA-00904: "MY_TABLE_PK": invalid identifier
How can we read the Primary Key value in those cases?
Thanks a lot for your time.
Your primary key INDEX is based upon a primary key COLUMN in your table as are all constraints.
You can select the primary key COLUMN but the INDEX is a seperate object in the database and cannot itself be selected (you would not want to anyhow). In your case, the primary key constraint itself is probably enforcing uniqueness in the primary key column(s) as well as decreasing search time by using an index.
I think you might be getting slightly confused in your terminology.
Query the
user_ind_columnsdictionary view to find the primary key column the index is based upon if you are unsure:Then add the underlying COLUMN(S) (there might be more than one) to your select query to have it returned.
Hope it helps…