14 Copyright © 2004, Oracle. All rights reserved. Using Materialized Views
14-2 Copyright © 2004, Oracle. All rights reserved. Objectives After completing this lesson, you should be able to: Use materialized views to access remote data using local queries Configure fast refresh for a materialized view
14-3 Copyright © 2004, Oracle. All rights reserved. Materialized Views Materialized views can be created to: –Replicate data to remote databases –Cache expensive queries in data warehouse environments A materialized view is a copy of a table or query result set from a single point in time. You can select data from a materialized view as you would from a table or view. The data in a materialized view can be synchronized with the source tables either manually or automatically at scheduled intervals.
14-4 Copyright © 2004, Oracle. All rights reserved. Refreshing Materialized Views To keep a materialized view up to date, it needs to be refreshed. There are three different ways to refresh a materialized view: –Complete –Fast –Force Pittsburgh Detroit
14-5 Copyright © 2004, Oracle. All rights reserved.
14-6 Copyright © 2004, Oracle. All rights reserved. Materialized View Logs Materialized view logs are used to support fast refresh for different types of materialized views. Materialized views which cannot fast refresh are called complex.
14-7 Copyright © 2004, Oracle. All rights reserved. Primary Key Materialized Views Uses the primary key of the source table to identify changed rows Default type of materialized view Requires an enabled primary key constraint on the source table CREATE MATERIALIZED VIEW job_mv REFRESH FAST START WITH sysdate NEXT sysdate + 1 WITH PRIMARY KEY AS SELECT * FROM
14-8 Copyright © 2004, Oracle. All rights reserved. Creating Materialized Views
14-9 Copyright © 2004, Oracle. All rights reserved. Updatable Materialized Views Updatable materialized views allow changes made at both the source site and the materialized view site to be synchronized: Materialized view changes are pushed up to the source site during refreshing. Changes to the source site are pulled down from source site during refreshing. Detroit Pull Push Pittsburgh
14-10 Copyright © 2004, Oracle. All rights reserved. Monitoring Materialized View Refresh Check the Database page for alerts: View materialized view details:
14-11 Copyright © 2004, Oracle. All rights reserved. Refresh Job Errors
14-12 Copyright © 2004, Oracle. All rights reserved. Monitoring Refresh Operations SELECT owner, mview_name, last_refresh_date FROM DBA_MVIEWS; OWN MVIEW_NAME LAST_REFRESH_DATE SH CAL_MONTH_SALES_MV 21-JAN :48 HR SITE1_JOBS 07-FEB :53 SELECT job, what, next_date, broken, failures FROM DBA_JOBS WHERE schema_user='HR'; JOB WHAT NEXT_DATE BROKEN FAILURES dbms_refresh.refresh('"HR"."SITE1_JOBS"'); 07-FEB-04 N 1
14-13 Copyright © 2004, Oracle. All rights reserved. Additional Distributed Data Technologies Oracle Change Data Capture Oracle Advanced Queuing Oracle Streams Gateway products and Generic Connectivity
14-14 Copyright © 2004, Oracle. All rights reserved.
14-15 Copyright © 2004, Oracle. All rights reserved. Summary In this lesson, you should have learned about: Using materialized views to access remote data using local queries Configuring fast refresh for a materialized view
14-16 Copyright © 2004, Oracle. All rights reserved.