下面刷新物化视图MV_T_NAME,刷新操作的判断依据是,只刷新SNAPTIME$$列大于当前物化视图的LAST_REFRESH_DATE的记录,由于物化视图日志中所有记录的SNAPTIME$$的值都比物化视图MV_T_ID_NAME上次刷新的时间点大,因此会刷新所有记录。对于SNAPTIME$$列的值是40000101 00:00:00的记录,物化视图会把SNAPTIME$$列的值更新为当前刷新时间,对于那些已经被更新过的SNAPTIME$$列,则保持原值。
zx@ORA11G>exec dbms_mview.refresh('MV_T_NAME');
PL/SQL procedure successfully completed.
zx@ORA11G>select mview_name,last_refresh_date, staleness from user_mviews;
MVIEW_NAME LAST_REFRESH_DATE STALENESS
------------------------------ ----------------- -------------------
MV_T_BOTH 20170809 15:45:10 NEEDS_COMPILE
MV_T_ID 20170809 15:58:30 NEEDS_COMPILE
MV_T_NAME 20170809 16:16:01 FRESH
zx@ORA11G>select * from mlog$_t;
ID NAME M_ROW$$ SEQUENCE$$ SNAPTIME$$ D O CHANGE_VECTOR$$ XID$$
-------------------- ---------- ------------------------------ -------------------- ----------------- - - ------------------------------ --------------------
1 zx AAAVs6AAEAAAAJVAAA 8 20170809 15:58:30 I N FE 2814882911093459
2 wl AAAVs6AAEAAAAJVAAB 9 20170809 15:58:30 I N FE 2814882911093459
3 yc AAAVs6AAEAAAAJVAAC 10 20170809 15:58:30 I N FE 2814882911093459
3 yc AAAVs6AAEAAAAJVAAC 11 20170809 15:58:30 U U 08 2814882911093459
3 yc AAAVs6AAEAAAAJVAAC 12 20170809 15:58:30 U N 08 2814882911093459
2 wl AAAVs6AAEAAAAJVAAB 13 20170809 15:58:30 D O 00 2814882911093459