Materialized View Samples

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Complete refresh(without on <commit/demand)( so by default commit)

create materialized view t5_c


2 tablespace tt
3 refresh complete
4 start with sysdate next sysdate + 1
5 with primary key
6* as select count(*) from t5@test2_lnk where id=2

SQL> /

Materialized view created.


SQL> select * from t5_c;
COUNT(*)
---------257
In server:
SQL> update t5 set id=2 where name='rocky';
769 rows updated.
SQL> select count(*) from t5 where id=2;
COUNT(*)
---------1026
In client:
SQL> select * from t5_c;
COUNT(*)
---------257
SQL> exec dbms_mview.refresh('t5_c','C');
PL/SQL procedure successfully completed.
SQL> select * from t5_c;
COUNT(*)257
In server:
SQL> commit;

Commit complete.
SQL> select count(*) from t5 where id=2;
COUNT(*)
---------1026
In client:
SQL> select count(*) from t5 @ test2_lnk where id=2;
COUNT(*)
---------1026
Commit: Once commit operation is done in server,then mv also updated or
commited automatically
Demand:Cant be updated automatically in MV.At the time of refresh,MV
will be updated.
Complete Refresh (On demand)
SQL> create materialized view t5_c1
2 tablespace tt
3 build immediate
4 refresh complete
5 on demand
6 start with sysdate next sysdate+1
7 with primary key
8 as select count(*) from t5 @ test2_lnk where id=2;
Materialized view created.
SQL>
SQL> select * from t5_c1;
COUNT(*)
---------1026

In server:

SQL> select count(*) from t5 where id=2;


COUNT(*)
---------1026
SQL> update t5 set id=2 where name='rocky';
1281 rows updated.
SQL> commit;
Commit complete.
SQL> select count(*) from t5 where id=2;
COUNT(*)
---------1538
In client:
SQL> select count(*) from t5 @ test2_lnk where id=2;
SQL> /
COUNT(*)
---------1026
SQL> select * from t5_c1;
COUNT(*)
---------1026
SQL> exec dbms_mview.refresh('t5_c1','C');
PL/SQL procedure successfully completed.
SQL> select * from t5_c1;
COUNT(*)
---------1538
Materialized using fast refresh:
In server:

Create materialized view log on t5 with rowid(id) including new values


//t5 table name .Need primary key for table t5 or row id.If use filter option such
as where ,mention the column in rowid.For updating new values ,type including
new values only for rowid .Not primary key table.
Materialized view log created.
SQL> select * from tab;
TNAME
TABTYPE CLUSTERID
------------------------------ ------- ---------MLOG$_T5
TABLE
T5
TABLE
T6
TABLE
In client:
create materialized view t5_mf
2 build immediate
3 refresh fast
4 on demand
5* as select count(*) from t5@test2_lnk where id=2
Materialized view created.
SQL> select * from t5_mf;
COUNT(*)
---------1538
In server:
SQL> update t5 set id=2 where name='rocky';
1793 rows updated.
SQL> select count(*) from t5 where id=2;
COUNT(*)
---------2050
SQL> commit;
Commit complete.
In client:
SQL> select * from t5_mf;
COUNT(*)
----------

1538
SQL> exec dbms_mview.refresh('t5_mf','F');
PL/SQL procedure successfully completed.
SQL> select * from t5_mf;
COUNT(*)
---------2050
Because of on demand , view will be updated after the refresh.

You might also like