查询以获取物化视图中的所有表

query to get all tables in a materialized view

朋友们下午好,

查询是否有任何方法(select * 来自)可视化哪些 table 形成物化视图? 例如:

CREATE MATERIALIZED VIEW table_vm
 
  REFRESH COMPLETE ON COMMIT
  as
SELECT * FROM table1;
UNION ALL
SELECT * FROM table2;

我想输出这样的东西:

视图名称 | table 姓名 table_m | Table 1 table_m | table 2 tabla_m | table 3 .... ....

非常感谢,

如有任何信息,我将不胜感激。

您可以使用视图 DBA_DEPENDENCIES 查看编译到数据库中的对象的任何依赖项。使用实体化视图的名称查询该视图应该列出所有表以及实体化视图所依赖的任何其他依赖项。 REFERENCED_OWNERREFERENCED_NAME 将保存实体化视图所使用的表的值。

SELECT *
  FROM dba_dependencies
 WHERE owner = 'OWNER_OF_MV' AND name = 'TABLE_MV';

一个选项是

SQL> create table t1 ( c1 number, c2 varchar2(1) ) ;

Table created.

SQL>  create table  t2 ( c1 number , c3 varchar2(1) ) ;

Table created.

SQL> create table t3  ( c1 number , c3 varchar2(1) ) ;

Table created.

SQL> create materialized view mv1 refresh complete on demand as
  2  select a.c1 , b.c3 as c2, c.c3
  3  from t1 a inner join t2 b on a.c1 = b.c1
  4   left join t3 c on a.c1 = c.c1 ;

Materialized view created.

SQL> select name as mv, listagg(referenced_name || ' - ' || referenced_type , '|' ) 
 within group ( order by referenced_name ) as list_dep
 from dba_dependencies where name='MV1' and name != referenced_name 
 group by name

MV                             LIST_DEP
------------------------------ --------------------------------------------------
MV1                            T1 - TABLE|T2 - TABLE|T3 - TABLE