Search notes:

Oracle: Columns of primary keys

The following select statement shows the (first 20) columns that participate in a primary key:
select
   pkc.owner,
   pkc.table_name,
   pkc.constraint_name,
   --
   max(case when col.position =  1 then col.column_name end) col_01,
   max(case when col.position =  2 then col.column_name end) col_02,
   max(case when col.position =  3 then col.column_name end) col_03,
   max(case when col.position =  4 then col.column_name end) col_04,
   max(case when col.position =  5 then col.column_name end) col_05,
   max(case when col.position =  6 then col.column_name end) col_06,
   max(case when col.position =  7 then col.column_name end) col_07,
   max(case when col.position =  8 then col.column_name end) col_08,
   max(case when col.position =  9 then col.column_name end) col_09,
   max(case when col.position = 10 then col.column_name end) col_20,
  
   max(case when col.position = 11 then col.column_name end) col_21,
   max(case when col.position = 12 then col.column_name end) col_22,
   max(case when col.position = 13 then col.column_name end) col_23,
   max(case when col.position = 14 then col.column_name end) col_24,
   max(case when col.position = 15 then col.column_name end) col_25,
   max(case when col.position = 16 then col.column_name end) col_26,
   max(case when col.position = 17 then col.column_name end) col_27,
   max(case when col.position = 18 then col.column_name end) col_28,
   max(case when col.position = 19 then col.column_name end) col_29,
   max(case when col.position = 20 then col.column_name end) col_20,
   --
   listagg(col.column_name, ', ') within group (order by col.position)  as cols
from
   all_constraints    pkc  join
   all_cons_columns   col on pkc.owner  = col.owner and
                             pkc.constraint_name = col.constraint_name
where
   pkc.constraint_type = 'P'        and
   pkc.owner           =  user
group by
   pkc.owner,
   pkc.table_name,
   pkc.constraint_name
order by
   pkc.owner,
   pkc.table_name
; 

See also

Columns of indices

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1740463539, '18.118.0.175', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/Oracle/objects/tables/constraints/primary-key/columns/index(79): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78