如何自动刷新实例化视图

时间:2019-01-08 11:31:18

标签: oracle view refresh materialized

创建实例化视图时,我想在将数据插入表后自动刷新实例化视图。

我尝试了以下代码(请刷新完整的Creating materialized view that refreshes every 5 min开头),但无法正常工作。这段代码也是每1分钟刷新一次的解决方案。

在插入数据时我想要一个解决方案。有可能吗?

Create Materialized view temp_mv refresh complete start with (sysdate) next (sysdate+1/1440) with rowid as select * from temp;

1 个答案:

答案 0 :(得分:1)

您可以尝试执行此操作,但不适用于更复杂的视图。

  --create table
    create table temp (a int not null primary key);


    -- create table log; 
    create materialized view log on temp
    with primary key
    including new values;

    --create view 
    create materialized view temp_mv
    build immediate 
    refresh fast
    on commit
    as
    select * from temp;


    -- populate table 
    insert into  temp select level from dual connect by level <100;

    select * from temp_mv; -- no value 

    commit; -- view is refreshed


    select * from temp_mv; -- all values