我想出了一个显示特定所有者的所有表和视图的查询。我现在要做的是,但我遇到了一个问题,就是我希望有一个第二列,逐行显示该字段是“表”还是“视图”。这可能吗?如果是的话,我该怎么做呢?
select table_name
from all_tables
where owner = '<owner>'
UNION
select view_name
from all_views
where owner = '<owner>'
order by table_name;
答案 0 :(得分:1)
我使用all_objects
代替
select object_name, object_type
from all_objects
where object_type in ('TABLE', 'VIEW')
and owner = <<schema name>>
order by object_name
答案 1 :(得分:1)
我自己更喜欢xxx_objects视图用于此目的(正如Justin所说),但如果您特别需要表格和视图中的其他数据,则可以添加额外的信息:
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,因为两个结果集之间不会发生冲突。