DIFFERENCE BETWEEN View and Materialized View is that Views are not stored physically on the disk.View can be defined as a virtual table created as a result of the query but Materialized View is a physical copy of base table
MATERIALIZED VIEW
A materialized view is a table segment whose contents are periodically refreshed based on a query
Data can be summarized and distributed in the form of Materialized views.
ADVANTAGES OF MATERIALIZED VIEWS ARE
Replication of data between sites.
Performance Improvement
BUILD Options
IMMEDIATE: The materialized view is populated immediately.
DEFERRED: The materialized view is populated on the first refresh.
refresh types available are
FAST: if we give fast refresh . If materialized view logs are not present for source tables in advance, the creation fails.
COMPLETE: The table segment supporting the materialized view is truncated(structure of the database wont change only the data will be deleted) and repopulated completely using the associated query.
FORCE: A fast refresh is given If is not possible a complete refresh is performed.
refresh can be triggered in 2 ways,
ON COMMIT: The refresh is triggered by a committed data change
ON DEMAND: The refresh is initiated by a manual request
Materialized Views with ON COMMIT
ON COMMIT ensures that changes are reflected as soon changes are done in the base tables.
before
After
Materialized Views with ON DEMAND
Refresh the Materialized view. MANUALLY(by package)
EXEC DBMS_MVIEW.REFRESH(‘SALES_DE_MV1’);
Materialized Views with REFRESH FAST
The following things are to be considered,
Based on the availability of materialized view logs an incremental refresh happens.
Fast refresh mview can be created based on master tables
Mview based on a synonym or a view a refresh fast option cannot be used
Mview are not eligible for fast refresh if it contains any analytical function
Step 1: First create a Materialized view Log.
Step 2: Now create the mview for fast refresh