oracle refresh force,解决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;

解决oracle 物化视图刷新失败

标签:order   必须   upd   提交   生效   and   ant   ext   还需要

本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉 本文系统来源:http://www.cnblogs.com/penghaihang/p/7610467.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值