Refresh a materialized view

To refresh a Materialized view we need DBMS_SNAPSHOT.REFRESH procedure.

Preview

Steps.

CREATE TABLE demo_m
(
   id     NUMBER (10) primary key,
   name   VARCHAR2 (400)
);
/
INSERT INTO DEMO_M (
   ID, NAME)
VALUES (1001, 'VIKAS' );
/
SELECT * FROM demo_m;

Preview

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;

Preview

One record is also in view. Now insert into table.

INSERT INTO DEMO_M (
   ID, NAME)
VALUES (1002, 'PANDEY' );
SELECT * FROM demo_m;

Preview

One record added.

check view-

Select * from  emp_m_view;

Preview

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;

Preview

Now data is refreshed in materialized view.

You might Like


comments powered by Disqus