Materialized view became INVALID and USER_MVIEWS.COMPILE_STATE becomes ‘NEEDS_COMPILE’

materialized-vieworacleoracle-11g-r2

I have an application which is getting data from Oracle(11.2.0.4) Materialized view, there is expected behaviour about materialized view will go INVALID when
any DML action happens on the associated tables or assocaited objects are invalid.

My materialized view opotions are as listed below and confirming that associated objects are valid all the time.

CREATE materialized VIEW mv_emp_test1 
NOLOGGING COMPRESS build IMMEDIATE 
REFRESH FORCE 
START WITH (SYSDATE) NEXT (SYSDATE+5/1024)
as
......

Materialized view go into INVALID state when it freshes after every 5 minutes and become valid if any of the following method applied:

alter materialized view mv_emp_test1 recompile;
or
exec dbms_mview.refresh('mv_emp_test1');

Also, checked related documents and bugs, Doc ID 264036.1 in metalink has included the exact scenario but didn't find proper workaround so that auto refresh in every 5 minutes.

Best Answer

That is the expected behaviour.

If the data in the base table changes and the view isn't up to date anymore its status is not valid anymore. If you recompile or refresh it will become up to date and is valid again. So you don't have to bother about the invalid state of your view.

This question was already posed on stackoverfow.com and answered by Andrew Brennan:

See MOS Doc ID 264036.1:

Dependencies related to MVs are automatically maintained to ensure correct operation. When an MV is created, the materialized view depends on the master tables referenced in its definition. Any DML operation, such as an INSERT, or DELETE, UPDATE, or DDL operation on any dependency in the materialized view will cause it to become invalid.