1、创建测试表
SQL> CREATE TABLE t_M
2 AS
3 SELECT * FROM all_objects;
Table created
2、查询测试表中记录
SQL> select count(*) from t_m;
COUNT(*)
———-
48941
3、创建中间表
SQL> create table t_m_n as
2 select * from t_m where 1=0;
Table created
4、查询中间表记录
SQL> select count(*) from t_m_n;
COUNT(*)
———-
0
5、创建刷新物化视图
SQL> CREATE MATERIALIZED VIEW t_m_n
on prebuilt TABLE WITH REDUCED PRECISION
REFRESH FORCE
ON DEMAND
AS
SELECT * FROM t_m;
Materialized view created
6、执行物化视图刷新
SQL> exec dbms_mview.refresh(‘T_M_N’);
PL/SQL procedure successfully completed
7、查询物化视图中记录数
SQL> select count(*) from t_m_n;
COUNT(*)
———-
48941
8、删除物化视图
SQL> DROP MATERIALIZED VIEW T_M_N;
Materialized view dropped
9、查询中间表中条数
SQL> select count(*) from t_m_n;
COUNT(*)
———-
48941
10、后续可能操作
1)t_m和t_m_n相互重命名,实现在线修移动表的位置、改表结构、降低高水位等操作,同(shrink)
2)和dblink结合,实现数据的跨版本迁移