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;