Materialized view with refresh triggered Mode in Oracle
Materialized view with refresh triggered Mode in Oracle :-
The BUILD clause options are shown below.
IMMEDIATE
|
The materialized view is populated immediately.
|
DEFERRED
|
The materialized view is populated on the first requested refresh.
|
The following refresh types are available.
FAST
|
A fast refresh is attempted. If materialized view logs are not present against the source tables in advance, the creation fails.
|
COMPLETE
|
The table segment supporting the materialized view is truncated and repopulated completely using the associated query.
|
FORCE
|
A fast refresh is attempted. If one is not possible a complete refresh is performed.
|
A refresh can be triggered in one of two ways.
ON COMMIT
|
The refresh is triggered by a committed data change in one of the dependent tables.
|
ON DEMAND
|
The refresh is initiated by a manual request or a scheduled task.
|
A refresh can be triggered in one of two ways.
--========MATERIALIZED
VIEW === with refresh Trigger Options ========
A refresh can
be triggered in one of two
ways.
ON COMMIT : The refresh is
triggered by a committed data change in one of the
dependent tables.
ON DEMAND : The refresh is
initiated by a manual
request or a
scheduled task.
CREATE MATERIALIZED VIEW
XXSD_EMP_M_V
BUILD IMMEDIATE
REFRESH FORCE
ON DEMAND
AS
SELECT * FROM xxsd_emp_tl where
deptno = 10
DROP MATERIALIZED VIEW
XXSD_EMP_M_V
select * from
XXSD_EMP_M_V
update xxsd_emp_tl
set COMM
= NVL(COMM,0)+1000
where
deptno = 10
select * from xxsd_emp_tl
where
deptno = 10
commit;
select * from
XXSD_EMP_M_V
EXEC DBMS_MVIEW.refresh('XXSD_EMP_M_V');
--======================
ON COMMIT --====================
@@@
Example 1 with single table -----
--======================
ON COMMIT --====================
create table XXSD_EMP (
emp_no
number,
emp_name
varchar(100),
dept_no
number,
CONSTRAINT
emp_pk Primary Key (emp_no)
)
select * from XXSD_EMP
insert into XXSD_emp values (1,'Manoj',10);
insert into XXSD_emp values (2,'Sanjay',20);
COMMIT;
select * from XXSD_EMP
--====================================================
I
created materialized view logs
on
these tables with rowid and materialized views as
follows:
--====================================================
create materialized view XXSD_empdept_mv
BUILD IMMEDIATE
REFRESH FORCE
ON COMMIT
as
select * from XXSD_emp
create materialized view log on XXSD_emp
select * from XXSD_emp
select * from XXSD_empdept_mv
--====================================================
insert into XXSD_emp values (3,'JP',30);
commit;
select * from XXSD_empdept_mv;
--=============
insert into XXSD_emp values (4,'Ravi',40);
commit;
--====================================================
DROP TABLE XXSD_EMP
DROP materialized view XXSD_empdept_mv
--========================
@@@@
Example 2 with Double table
DROP TABLE XXSD_DEPT
DROP TABLE XXSD_EMP
DROP materialized view XXSD_empdept_mv
--====================================================
create table XXSD_DEPT (
dept_no
number ,
dept_name
varchar(32) ,
dept_desc
varchar(32),
CONSTRAINT
dept_pk Primary Key (dept_no)
)
select * from XXSD_DEPT
create table XXSD_EMP (
emp_no
number,
emp_name
varchar(100),
dept_no
number,
CONSTRAINT
emp_pk Primary Key (emp_no,dept_no)
)
select * from XXSD_EMP
insert into XXSD_dept values (10,'it','desc1');
insert into XXSD_dept values (20,'hr','desc2');
COMMIT;
insert into XXSD_emp values (1,'Manoj',10);
insert into XXSD_emp values (2,'Sanjay',20);
COMMIT;
select * from XXSD_EMP
select * from XXSD_DEPT
--====================================================
I
created materialized view logs
on
these tables with rowid and materialized views as
follows:
--====================================================
create materialized view log on XXSD_emp with rowid
create materialized view log on XXSD_dept with rowid
create materialized view XXSD_empdept_mv
refresh fast
on commit
as
select a.rowid
dept_rowid, b.rowid
emp_rowid, a.dept_no,b.emp_no,b.emp_name
from XXSD_dept a, XXSD_emp b
where a.dept_no=b.dept_no
select * from XXSD_empdept_mv
--====================================================
insert into XXSD_dept values (30,'it','desc3');
commit;
insert into XXSD_emp values (3,'JP',30);
commit;
select * from XXSD_empdept_mv;
--=============
insert into XXSD_dept values (40,'it','desc3');
commit;
insert into XXSD_emp values (4,'Ravi',40);
commit;
--==========================================================
Comments
Post a Comment