我想出了一个显示特定所有者的所有表和视图的查询。我现在想做的,但有一个问题,是我想有第二列,逐行指示该字段是“表”还是“视图”。这可能吗?如果是这样,我该怎么做?
select table_name
from all_tables
where owner = '<owner>'
UNION
select view_name
from all_views
where owner = '<owner>'
order by table_name;
我会all_objects
改用
select object_name, object_type
from all_objects
where object_type in ('TABLE', 'VIEW')
and owner = <<schema name>>
order by object_name
为此,我更喜欢自己的 xxx_objects 视图(正如贾斯汀所说),但如果您特别需要表格和视图视图中的其他数据,您可以添加额外的信息:
select 'Table' AS object_type, table_name
from all_tables
where owner = '<owner>'
UNION ALL
select 'View' AS object_type, view_name
from all_views
where owner = '<owner>'
order by table_name;
请注意,我已将其更改为使用 UNION ALL,因为两个结果集之间不会发生冲突。