Materialized view refresh

Hi Team,

I need an help in creating an materialzed view which will do a incremental refresh in the week days and full refresh in the weekends

The challenge is I want to how to refresh for the view as the view is created by select * from view name i.e it gets data from the view and base tables.
The below is the implementation
Create or replace viewname
as Select a.col1 ,b. Col2
from tab1 a , tab2 b
where a.col3=b.col4

Create or replace viewname1
as Select a.col3 ,b. Col5,b.col6
from tab1 a , tab2 b
where a.col1=b.col2

Create or replace viewname2
as Select a.col1 ,b. Col5,b.col6
from viewname a , viewname1 b
where a.col1=b.col2

Now the materialized view is created as below

Select * from viewname2;

I want to refresh the view in incremental during weekdays and full refresh on the weekends. Also when Iam trying to refresh the view , should I create the materialized log on the base tables or the views ?
Who is Participating?
johnsoneSenior Oracle DBACommented:
I don't believe that you can do a fast refresh of a materialized view based on views.  Maybe you can.  Going from memory though, but I believe that would be considered a complex view which wouldn't be eligible for fast refresh.  You can always try to create it with fast refresh and it will tell you if you can't do that.

What you really should be doing, is simplifying the query in the materialized view.  Your sample queries don't make sense because VIEWNAME2 is using a join on a column that doesn't exist in VIEWNAME1.  Taking a guess, this is what it should look like (assuming that the table names in the views aren't really the same).

SELECT a.col1, 
FROM   tab1 a, 
       tab2 b, 
       tab1 c, 
       tab2 d 
WHERE  a.col3 = b.col4 
       AND c.col1 = d.col2 
       AND a.col1 = d.col2; 

Open in new window

For the refresh schedule you want, I have no idea why you want to do both fast and complete refreshes.  If you really want that, I would suggest creating the view as fast refresh and then scheduling a job to do the completes when you want.  I also don't recall the effect of a complete refresh on the materialized view log, if it doesn't truncate it, then the database will have to process all the records anyway.

You would have to play with the setting of NEXT in the materialized view to get it to refresh only on weekdays.  It's possible.

Any materialized view logs would have to be created on the base tables.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.