『ORACLE』快速刷新物化视图的方法(11g)

1、on demand:使用DBMS_MVIEW包中的存储过程启用手工刷新(默认设置)

refresh [fast|complete|force] 视图刷新的方式:
complete:全部刷新。相当于重新执行一次创建视图的查询语句。
 
fast: 增量刷新.假设前一次刷新的时间为t1,那么使用fast模式刷新物化视图时,只向视图中添加t1到当前时间段内,主表变化过的数据.为了记录这种变化,建立增量刷新物化视图还需要一个物化视图日志表。create materialized view log on (主表名)。(多张表时,此语句也生效,创建后,原来的表中会多出两类视图表:MLOG$_table_name和RUPD$_table_name)
 
force: 这是默认的数据刷新方式。当可以使用fast模式时,数据刷新将采用fast方式;否则使用complete方式。

 

2、on commit:在事务提交后刷新

使用情况

⑴仅用于快速刷新的物化视图

⑵需要on commit refresh对象权限

⑶如果刷新失败需要进行手工刷新

3、never:禁止物化视图刷新

在计划时间进行刷新:使用start with 和next选项。从指定的时间开始,每隔一段时间(由next指定)就刷新一次;

比如说我们要全刷新一张mv_test物化视图:
begin
     dbms_mview.refresh(TAB=>'MV_TEST',
                                       METHOD=>'COMPLETE',
                                       PARALLELISM=>8);
end;
/
增量刷新就不需要使用什么并行了,通常情况下,是没有那个必要的。
begin
     dbms_mview.refresh(TAB=>'MV_TEST',
                                       METHOD=>'FAST',
                                       PARALLELISM=>1);
end;
/
 
或者,也可以这样执行:
exec dbms_mview.refresh('MV_TEST','F');
 
 

create matherialized view emp_data

pctfree 5 

tablespace example

storage (initial 50K next 50K)

refresh fast next sysdate + 7

as select ...;

create matherialized view emp_data

pctfree 5 

tablespace example

using index storage (initial 25K next 25K)

refresh start with round(sysdate + 1) + 11/24

next next_day(trunc(sysdate),'MONDAY') + 15/24

as select * from sh.customers@remote union

select * from sh.customers@local;

原文地址:https://www.cnblogs.com/KT-melvin/p/6753229.html