Oracle 不带'的表格列表;我没有主键

Oracle 不带'的表格列表;我没有主键,oracle,Oracle,需要从没有主键的架构中获取表名列表。我尝试了下面的查询来获得这个结果,但它将列出除主键之外的所有其他键 SELECT a.constraint_name,a.table_name FROM ALL_CONS_COLUMNS A JOIN ALL_CONSTRAINTS C ON A.CONSTRAINT_NAME = C.CONSTRAINT_NAME WHERE C.CONSTRAINT_TYPE not in('P') and a.owner ='my_schema'; 如果您只希望当前用

需要从没有主键的架构中获取表名列表。我尝试了下面的查询来获得这个结果,但它将列出除主键之外的所有其他键

SELECT a.constraint_name,a.table_name
FROM ALL_CONS_COLUMNS A
JOIN ALL_CONSTRAINTS C
ON A.CONSTRAINT_NAME = C.CONSTRAINT_NAME
WHERE
C.CONSTRAINT_TYPE not in('P')
and a.owner ='my_schema';

如果您只希望当前用户使用此视图,那么最好使用
user\u xxx
视图,而不是
all\u xxx
视图

以下操作应满足您的要求:

select ut.table_name
from user_tables ut
where not exists (select 1
                  from user_constraints ac
                  where ac.table_name = ut.table_name
                    and ac.constraint_type = 'P'
                  );
如果其他用户确实需要此功能,则可以使用以下功能

select at.*
from all_tables at
where not exists (select 1
                  from all_constraints ac
                  where ac.owner = at.owner
                    and ac.table_name = at.table_name
                    and ac.constraint_type = 'P'
                  )
and at.owner = 'MY_SCHEMA';
不要忘记Oracle是区分大小写的,用户名是以大写字母存储的,因此
a.owner='my_schema'
很可能不会返回任何内容。

像这样尝试

SELECT table_name 
FROM   all_tables A 
WHERE  table_name NOT IN 
     (
     SELECT table_name 
     FROM   all_constraints WHERE constraint_type ='P' 
     )
AND   a.owner = 'my_schema';
另一种方式:

select owner,table_name
from all_tables
where owner = 'my_schema' 
MINUS
select owner,table_name
from all_constraints
where owner = 'my_schema' 
and constraint_type = 'P'