Database View vs Materialized View & How to refresh Materialized Views

View
reduces the complexity of queries
is a virtual table, created using Create View command
is computed each time it is used or accessed => Slow Performance, No storage required
updates in tables reflect immediately in the View (and vice versa), however, view created using DISTINCT, Group By etc. cant be updated
Materialized View
is a physical, precomputed copy of the data => Fast access, storage required
Changes in original tables are not reflected in materialized views
Must be updated via triggers, or "REFRESH" instruction in view creation statement

See more: https://techdifferences.com/difference-between-view-and-materialized-view.html


How to refresh Materialized Views

CREATE MATERIALIZED VIEW my_view_1
   TABLESPACE ...
   REFRESH FAST NEXT sysdate + 7
   AS SELECT * FROM ...;
"The statement does not include a START WITH parameter, so Oracle Database determines the first automatic refresh time by evaluating the NEXT value using the current SYSDATE. A materialized view log was created for the employee table, so Oracle Database performs a fast refresh of the materialized view every 7 days, beginning 7 days after the materialized view is created."


CREATE MATERIALIZED VIEW my_view_2
   TABLESPACE ...
   REFRESH START WITH ROUND(SYSDATE + 1) + 11/24
   NEXT NEXT_DAY(TRUNC(SYSDATE), 'MONDAY') + 15/24
   AS SELECT * FROM ...;
"Oracle refreshes this materialized view tomorrow at 11:00 a.m. and subsequently every Monday at 3:00 p.m." 

http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_6002.htm

Comments