This is a draft cheat sheet. It is a work in progress and is not finished yet.
Materialized View
Simplest way to replicate data between sites or transform data format |
grant CREATE MATERIALIZED VIEW system privilege |
grant CREATE TABLE or CREATE ANY TABLE system privilege |
Syntax
CREATE MATERIALIZED VIEW view-name |
BUILD [IMMEDIATE | DEFERRED] or ON PREBUILT TABLE |
affect 1st populate data |
REFRESH [FAST | COMPLETE | FORCE ] |
fast need logs present, complete truncate the table |
ON [COMMIT | DEMAND ] |
commit rely on source data change; |
[[ENABLE | DISABLE] QUERY REWRITE] |
AS SELECT ...; |
Gether stats
exec DBMS_STATS.gather_table_stats(
ownname => 'SCOTT',
tabname => 'EMP_MV');
|
Create Materialized View Log
CREATE MATERIALIZED VIEW LOG
ON scott.emp
TABLESPACE users
WITH PRIMARY KEY
INCLUDING NEW VALUES;
|
|
|
Refresh Materialized Views
--only when ON DEMAND is used
EXEC DBMS_MVIEW.refresh('EMP_MV');
--regular refresh with oracle scheduler
using oracle scheduler call DBMS_MVIEW.refresh
--regular refresh with dbms_refresh package
use dbms_refresh.make then add
BEGIN
DBMS_REFRESH.make(
name => 'SCOTT.MINUTE_REFRESH',
list => '',
next_date => SYSDATE,
interval => '/1:Mins/ SYSDATE + 1/(60*24)',);
END;
BEGIN
DBMS_REFRESH.add(
name => 'SCOTT.MINUTE_REFRESH',
list => 'SCOTT.EMP_MV',
lax => TRUE);
END;
|
Considerations
populate and refresh MV add additional loads |
if not regular refreshed, MV logs are not necessary |
fast refreshes may not be possible, due to Oracle version and the complexity of the associated query |
QUERY_REWRITE_INTEGRITY and QUERY_REWRITE_ENABLED parameter need to be set for query rewrite |
|