Materialized views are schema objects that can be used to summarize,
compute, replicate, and distribute data. They are suitable in various computing environments such as data warehousing, decision support, and distributed or mobile computing: In data warehouses, materialized views are used to compute and store aggregated data such as sums and averages. Materialized views in these environments are typically referred to as summaries because they store summarized data. They can also be used to compute joins with or without aggregations. If compatibility is set to Oraclei or higher, then materialized views can be used for !ueries that include filter selections. The optimizer can use materialized views to improve !uery performance by automatically recognizing when a materialized view can and should be used to satisfy a re!uest. The optimizer transparently rewrites the re!uest to use the materialized view. "ueries are then directed to the materialized view and not to the underlying detail tables or views. In distributed environments, materialized views are used to replicate data at distributed sites and synchronize updates done at several sites with conflict resolution methods. The materialized views as replicas provide local access to data that otherwise have to be accessed from remote sites. In mobile computing environments, materialized views are used to download a subset of data from central servers to mobile clients, with periodic refreshes from the central servers and propagation of updates by clients bac# to the central servers. Materialized views are similar to inde$es in several ways: They consume storage space. They must be refreshed when the data in their master tables changes. They improve the performance of %"& e$ecution when they are used for !uery rewrites. Their e$istence is transparent to %"& applications and users. 'nli#e inde$es, materialized views can be accessed directly using a SELECT statement. (epending on the types of refresh that are re!uired, they can also be accessed directly in an INSERT, UPDATE, or DELETE statement. ) materialized view can be partitioned. *ou can define a materialized view on a partitioned table and one or more inde$es on the materialized view. Refresh Materialized Views Oracle maintains the data in materialized views by refreshing them after changes are made to their master tables. The refresh method can be incremental +fast refresh, or complete. -or materialized views that use the fast refresh method, a materialized view log or direct loader log #eeps a record of changes to the master tables. Materialized views can be refreshed either on demand or at regular time intervals. )lternatively, materialized views in the same database as their master tables can be refreshed whenever a transaction commits its changes to the master tables. Materialized View Logs ) materialized view log is a schema object that records changes to a master table.s data so that a materialized view defined on the master table can be refreshed incrementally. /ach materialized view log is associated with a single master table. The materialized view log resides in the same database and schema as its master table. /g. CREATE MATERIALIZED VIEW sales_by_month_by_state TABLESPACE examle PARALLEL ! BUILD IMMEDIATE RE"RES# C$MPLETE ENABLE %UER& REWRITE AS SELECT t'(alen)a*_month_)es(+ ('(,st_state_*o-.n(e+ SUM/s'amo,nt_sol)0 AS s,m_sales "R$M t.mes t+ sales s+ (,stome*s ( W#ERE s't.me_.) 1 t't.me_.) AND s'(,st_.) 1 ('(,st_.) 2R$UP B& t'(alen)a*_month_)es(+ ('(,st_state_*o-.n(e3 4 REFRESH 4 4 FAST 5 COMPLETE 5 FORCE 6 5 ON 4 DEMAND 5 COMMIT 6 5 4 START WITH 5 NEXT 6 )ate 5 WITH 4 PRIMARY KEY 5 ROWID 6 5 USING 4 DEFAULT 7 MASTER 5 LOCAL 8 ROLLBACK SEGMENT 5 7 MASTER 5 LOCAL 8 ROLLBACK SEGMENT *ollba(9_se:ment 6 7 DEFAULT 7 MASTER 5 LOCAL 8 ROLLBACK SEGMENT 5 7 MASTER 5 LOCAL 8 ROLLBACK SEGMENT *ollba(9_se:ment 8''' 5 USING 4 ENFORCED 5 TRUSTED 6 CONSTRAINTS 6 7 4 FAST 5 COMPLETE 5 FORCE 6 5 ON 4 DEMAND 5 COMMIT 6 5 4 START WITH 5 NEXT 6 )ate 5 WITH 4 PRIMARY KEY 5 ROWID 6 5 USING 4 DEFAULT 7 MASTER 5 LOCAL 8 ROLLBACK SEGMENT 5 7 MASTER 5 LOCAL 8 ROLLBACK SEGMENT *ollba(9_se:ment 6 7 DEFAULT 7 MASTER 5 LOCAL 8 ROLLBACK SEGMENT 5 7 MASTER 5 LOCAL 8 ROLLBACK SEGMENT *ollba(9_se:ment 8''' 5 USING 4 ENFORCED 5 TRUSTED 6 CONSTRAINTS 8''' 5 NEVER REFRESH 6 NEVER REFRESH Clause %pecify NEVER RE"RES# to prevent the materialized view from being refreshed with any Oracle (atabase refresh mechanism or pac#aged procedure. Oracle (atabase will ignore any RE"RES# statement on the materialized view issued from such a procedure. To reverse this clause, you must issue an ALTER MATERIALIZED VIEW ... RE"RES# statement. BUILD { IMMEDIATE | DEFERRED } The build_clause lets you specify when to populate the materialized view. IMMEI!"E %pecify IMMEDIATE to indicate that the materialized view is to be populated immediately. This is the default. EFERRE %pecify DE"ERRED to indicate that the materialized view is to be populated by the ne$t RE"RES# operation. The first +deferred, refresh must always be a complete refresh. 'ntil then, the materialized view has a staleness value of UNUSABLE, so it cannot be used for !uery rewrite. #$ER% RE&RI"E Clause The %UER& REWRITE clause lets you specify whether the materialized view is eligible to be used for !uery rewrite. EN!'LE Clause %pecify ENABLE to enable the materialized view for !uery rewrite. Restrictio(s o( E(a)li(g #uer* Rewrite /nabling of !uery rewrite is subject to the following restrictions: *ou can enable !uery rewrite only if all user0defined functions in the materialized view are DETERMINISTIC. *ou can enable !uery rewrite only if e$pressions in the statement are repeatable. -or e$ample, you cannot include CURRENT_TIME or USER, se!uence values +such as the CURRVAL or NE;TVAL pseudo columns,, or the SAMPLE clause +which may sample different rows as the contents of the materialized view change,. Notes+ "uery rewrite is disabled by default, so you must specify this clause to ma#e materialized views eligible for !uery rewrite. )fter you create the materialized view, you must collect statistics on it using the DBMS_STATS pac#age. Oracle (atabase needs the statistics generated by this pac#age to optimize !uery rewrite.