Here is a workaround to Oracle's bug:
alter materialized view MV_NAME nocache;
BEGIN DBMS_SNAPSHOT.REFRESH( MV_NAME,'C'); end;
alter materialized view MV_NAME cache;
Vra
I have two tables, TABLE_1
and TABLE_2
. Then we have a synonym called TABLE
that points to either TABLE_1
or TABLE_2
. When TABLE_1
is active, an ETL populates TABLE_2
and when the run is complete, it switches the TABLE
synonym to TABLE_2
to make it the active table. Then I have a materialized view that does something like this as the SQL: select * from TABLE
. What I am seeing happen is that after the materialize view runs the first time, it caches the actual table the synonym is pointing too. So when the ETL runs and flips the synonym to point at TABLE_2
, when a complete refresh is done on the materialized view, it still thinks the synonym is pointed at TABLE_1
. Why when I do a complete refresh does the materialized view not pick up the new synonym pointer to TABLE_2
?
Oplossing
Here is a workaround to Oracle's bug:
alter materialized view MV_NAME nocache;
BEGIN DBMS_SNAPSHOT.REFRESH( MV_NAME,'C'); end;
alter materialized view MV_NAME cache;
Ander wenke
I cannot find anything useful in Oracle documentation but just enable the logic:
TABLE
with some specific structure (dependent on your query structure) and the rule to refresh the table (as far as I remember it is called SUMMARY
, but the name does not play any role here)That's why I would say it is the only way to prevent the errors: reference the real target instead of synonym for creating materialized view.
So, the answer is: because the materialized view is a static table-like object dependent on the data set it is selecting; that's why to prevent the inconsistencies materialized view references the real object.
Sometimes I really wonder how many details Oracle hides inside.