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!

Get Primary Key and Value

Angus123May 29 2020 — edited Jul 7 2020

Hi

I have the following code to find the columns that make up a primary key for a table.

Results will differ for other tables

select  cols.column_name colname

        from all_constraints cons, all_cons_columns cols

        where cols.table_name = trim (upper ('MY_TABLE'))

        and cons.constraint_type = 'P'

        and cons.constraint_name = cols.constraint_name

        and cons.owner = cols.owner

        order by cols.table_name, cols.position

which returns

COLUMN_NAME

MY_COL_1

MY_COL_2

MY_COL_3

I need to write to a log table the

ID

FIELD_NAME

FIELD_VALUE

FIELD_NAME would be the concatinated primary key column names

and

FIELD_VALUE would be the concatinated primary key values

Not sure where to start

Any help appreciated

Regards

Gus

This post has been answered by Paulzip on May 29 2020
Jump to Answer
Comments
Post Details
Added on May 29 2020
2 comments
3,578 views