zoukankan      html  css  js  c++  java
  • 解决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;
    

      

      

  • 相关阅读:
    php,asp.net web开发B/S编程语言函数|参数|使用手册
    [share]深入探讨PHP中的内存管理问题
    Nginx环境下Php安装
    熟悉iWebSNS开发规约
    php判断浏览器和语言
    PHP实现动态生成饼状图、柱状图和折线图(转)
    cloudServer Amazon EC2 / AWS / SWS / yunjisuan / yunfuwu / yuncunchu
    read_humor_video
    pics
    JAVA XML / dom / jdom / dom4j / sax / stax / StAX Stream / StAX Event
  • 原文地址:https://www.cnblogs.com/penghaihang/p/7610467.html
Copyright © 2011-2022 走看看