解決oracle 物化視圖刷新失敗


oracle 物化視圖刷新失敗可能原因:

1.視圖未建立物化視圖日志

2.基表為授權給用戶

 

1.物化視圖語法

create materialized view [view_name]
refresh [fast|complete|force]
[
on [commit|demand] |
start with (start_time) next (next_time)
]
as
{創建物化視圖用的查詢語句}
以上是Oracle創建物化視圖(Materialized View,以下簡稱MV)時的常用語法,各參數的含義如下:
1.refresh [fast|complete|force] 視圖刷新的方式:
fast: 增量刷新.假設前一次刷新的時間為t1,那么使用fast模式刷新物化視圖時,只向視圖中添加t1到當前時間段內,
主表變化過的數據.為了記錄這種變化,建立增量刷新物化視圖還需要一個物化視圖日志表。create materialized view log on (主表名)。
(多張表時,此語句也生效,創建后,原來的表中會多出兩類視圖表:MLOG$_table_name和RUPD$_table_name)
 
complete:全部刷新。相當於重新執行一次創建視圖的查詢語句。
force: 這是默認的數據刷新方式。當可以使用fast模式時,數據刷新將采用fast方式;否則使用complete方式。

2.MV數據刷新的時間:
on demand:在用戶需要刷新的時候刷新,這里就要求用戶自己動手去刷新數據了(也可以使用job定時刷新)
on commit:當主表中有數據提交的時候,立即刷新MV中的數據;
start ……:從指定的時間開始,每隔一段時間(由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');

2. 建立基表的物化視圖日志 

-- tablename 為基表 with后面可以接主鍵,rowid  primary key是主鍵,rowid是表更新涉及的行號,sequence是序列對,自由添加。 
--including new values必須包含
create materialized view log on tablename with primary key,rowid,sequence (AREA_NM_R, AREA_NM_N) including new values;

3. 賦予主表的權限給建立視圖的用戶

grant select on tabelname to A;

4.示例

--1. 建立基表的物化視圖日志 
create materialized view log on auth_role with rowid, sequence (role_id, role_ad, bpm_group, role_name, role_enable, role_type, order_num) including new values ;
--2. 授權
grant select on sys_role to auth;
--3. 創建物化視圖
create materialized view viewname
refresh force on demand
start with SYSDATE next SYSDATE + NUMTODSINTERVAL(2,'MINUTE') 
as
select role_id, role_ad, bpm_group, role_name, role_enable, role_type, order_num, 'auth' sys_code from auth_role
union all
select role_id, role_ad, bpm_group, role_name, role_enable, role_type, order_num, 'bpm' sys_code from cfcap.sys_role
union all
select role_id, role_id role_ad, role_id bpm_group, role_name, 
to_number(ROLE_STAT) role_enable,to_char(role_type)||'' role_type, 
0 order_num, 'wbs' sys_code from forms.ts_role;

  

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM