SQL> select column_name,tt.CONSTRAINT_TYPE from all_cons_columns t,ALL_CONSTRAINTS tt 2 where t.table_name=tt.table_name and t.owner=tt.owner 3 and t.CONSTRAINT_NAME=tt.CONSTRAINT_NAME and tt.CONSTRAINT_TYPE='P' 4 and t.table_name='DEPT' and t.owner='SCOTT';COLUMN_NAME -------------------------------------------------------------------------------- C - DEPTNO P 已用时间: 00: 00: 00.01 SQL>
或者 SQL> select COLUMN_NAME from user_cons_columns where table_name = 'EMP' and owner='SCOTT' 2 and CONSTRAINT_NAME like 'PK_%';COLUMN_NAME -------------------------------------------------------------------------------- EMPNO已用时间: 00: 00: 00.20 SQL>
2 where t.table_name=tt.table_name and t.owner=tt.owner
3 and t.CONSTRAINT_NAME=tt.CONSTRAINT_NAME and tt.CONSTRAINT_TYPE='P'
4 and t.table_name='DEPT' and t.owner='SCOTT';COLUMN_NAME
--------------------------------------------------------------------------------
C
-
DEPTNO
P
已用时间: 00: 00: 00.01
SQL>
SQL> select COLUMN_NAME from user_cons_columns where table_name = 'EMP' and owner='SCOTT'
2 and CONSTRAINT_NAME like 'PK_%';COLUMN_NAME
--------------------------------------------------------------------------------
EMPNO已用时间: 00: 00: 00.20
SQL>