Oracle: Fast Refresh Materialized View with Joins

Step 1: Create Materialized View Log with Rowid on Each Table
create materialized view log on emp with rowid;
create materialized view log on dept with rowid;




Step 2: Create Materialized View with rowids for all the base tables

create materialized view empdept_mv
refresh fast on commit as
select
    e.rowid e_rowid,
    d.rowid d_rowid,
    e.empno,
    e.ename,
    d.deptno,
    d.dname,
from
    emp e,
    dept d
where
    e.deptno = d.deptno;



DONE :)

----------------------------------------------------------------------------------------------------------

NOTE: Restrictions on Fast Refresh on Materialized Views with Joins Only
-    All restrictions from "General Restrictions on Fast Refresh".
-    They cannot have GROUP BY clauses or aggregates.
-    Rowids of all the tables in the FROM list must appear in the SELECT list of the query.
-    Materialized view logs must exist with rowids for all the base tables in the FROM list of the query.
-    You cannot create a fast refreshable materialized view from multiple tables with simple joins that include an object type column in the SELECT statement.

6 comments:

  1. Hi all! can anyone explain me why are we using build immediate in materialized views.?? And also why do we use REFRESH FORCE ON DEMAND when we have dbms_mview.refresh??

    ReplyDelete
    Replies
    1. there are 2 options to build a mview build immediate & build deferred. The materialized view does not initially contain any data if build method is DEFERRED. A complete refresh is required for the first refresh of a build deferred materialized view.

      Delete
    2. REFRESH FORCE ON DEMAND is ofcoure on demand refresh, REFRESH FORCE to take advantage of fast refresh when it is possible. This needs to be refreshed manually using dbms_mview.refresh or dbms_refresh.refresh.

      Delete
  2. Hi Nimish ;

    May i know the difference between Master table Vs Local Base table. I am getting confused. Where to get all basic table information when creating materialized view?

    ReplyDelete
    Replies
    1. I think both Master table and Base table are same. Just different words to use same item.

      Delete
  3. Thanks buddy. This post was really helpful

    ReplyDelete