To refresh a Materialized view we need DBMS_SNAPSHOT.REFRESH procedure.
Steps.
One record is available in the table.
Create Materialized view.
One record is also in view.
Now insert into table.
One record added.
check view-
Still one record which was inserted before creating materialized view.
now to refresh this records in view we need to run the DBMS_SNAPSHOT.REFRESH procedure.
Check view data.
Now data is refreshed in materialized view.
Steps.
CREATE TABLE demo_m
(
id NUMBER (10) primary key,
name VARCHAR2 (400)
);
/
INSERT INTO TEST1.DEMO_M (
ID, NAME)
VALUES (1001, 'ASHISH' );
/
SELECT * FROM demo_m;
One record is available in the table.
Create Materialized view.
CREATE MATERIALIZED VIEW emp_m_view
--BUILD IMMEDIATE --
REFRESH
--Fast
--Complete
FORCE
ON --COMMIT
DEMAND
AS
SELECT * FROM demo_m;
/
Select * from emp_m_view;
Now insert into table.
INSERT INTO TEST1.DEMO_M (
ID, NAME)
VALUES (1002, 'SAHAY' );
SELECT * FROM demo_m;
One record added.
check view-
Select * from emp_m_view;
Still one record which was inserted before creating materialized view.
now to refresh this records in view we need to run the DBMS_SNAPSHOT.REFRESH procedure.
BEGIN
DBMS_SNAPSHOT.REFRESH('emp_m_view'); -- View name as parameter
END;
/
Check view data.
Select * from emp_m_view;
Now data is refreshed in materialized view.
No comments:
Post a Comment
Please do not add any spam links or abusive comments.