oracle 10g
SELECT A2.TABLE_NAME, WM_CONCAT(A2.COLUMN_NAME) AS “COLUMN_NAME”
FROM ALL_CONSTRAINTS A1, ALL_CONS_COLUMNS A2
WHERE UPPER(A1.TABLE_NAME) LIKE ‘TB_M30%’
AND UPPER(A1.OWNER) = ‘MESUSER’
AND A1.TABLE_NAME = A2.TABLE_NAME
AND A1.OWNER = A2.OWNER
AND A1.CONSTRAINT_NAME = A2.CONSTRAINT_NAME
AND A1.CONSTRAINT_TYPE = ‘P’
GROUP BY A2.TABLE_NAME
———————————————————————-
oracle 11g
SELECT A2.TABLE_NAME, LISTAGG(A2.COLUMN_NAME, ‘,’) WITHIN GROUP (ORDER BY A2.POSITION) “COLUMN_NAME”
FROM ALL_CONSTRAINTS A1, ALL_CONS_COLUMNS A2
WHERE UPPER(A1.TABLE_NAME) LIKE ‘TB_M30%’
AND UPPER(A1.OWNER) = ‘MESUSER’
AND A1.TABLE_NAME = A2.TABLE_NAME
AND A1.OWNER = A2.OWNER
AND A1.CONSTRAINT_NAME = A2.CONSTRAINT_NAME
AND A1.CONSTRAINT_TYPE = ‘P’
GROUP BY A2.TABLE_NAME