物化视图 MATERIALIZED VIEW

物化视图:

CREATE MATERIALIZED VIEW语法



CREATE MATERIALIZED VIEW [ schema. ] materialized_view
  [ column_alias [ENCRYPT [encryption_spec]] [, column_alias [ENCRYPT [encryption_spec]] ]... ]
  [ OF [ schema. ] object_type ]
  [ (scoped_table_ref_constraint) ]
  { ON PREBUILT TABLE [ { WITH | WITHOUT } REDUCED PRECISION ]
  | physical_properties materialized_view_props
  }
  [ USING INDEX [ physical_attributes_clause
    | TABLESPACE tablespace
    ]...
  | USING NO INDEX ]
  [ create_mv_refresh ]
  [ FOR UPDATE ]
  [ { DISABLE | ENABLE } QUERY REWRITE ] AS subquery ;



{ REFRESH { { FAST | COMPLETE | FORCE }

  | { ON DEMAND | ON COMMIT }
  | { START WITH date | NEXT date 
    }...
  | WITH { PRIMARY KEY | ROWID }
  | USING { DEFAULT [ MASTER | LOCAL ] ROLLBACK SEGMENT | [ MASTER | LOCAL ] ROLLBACK SEGMENT rollback_segment
     }...
  | USING { ENFORCED | TRUSTED } CONSTRAINTS }...
| NEVER REFRESH }  create_mv_refresh:

Use the create_mv_refresh clause to specify the default methods, modes, and times for the database to refresh the materialized view. If the master tables of a materialized view are modified, then the data in the materialized view must be updated to make the materialized view accurately reflect the data currently in its master tables. This clause lets you schedule the times and specify the method and mode for the database to refresh the materialized view.
用create_mv_refresh子句指定数据库刷新物化视图的默认方法,模式和时间。 如果物化视图的主表被修改,则必须更新物化视图中的数据,使物化视图准确反映其主表中当前的数据。 此子句允许您安排时间,并指定数据库的方法和模式来刷新物化视图。

Note:
This clause only sets the default refresh options. For instructions on actually implementing the refresh, refer to Oracle Database Advanced Replication and Oracle Database Data Warehousing Guide.

See Also:

    "Periodic Refresh of Materialized Views: Example" and "Automatic Refresh Times for Materialized Views: Example"

    Oracle Database PL/SQL Packages and Types Reference for more information on refresh methods

FAST Clause:

Specify FAST to indicate the incremental refresh method, which performs the refresh according to the changes that have occurred to the master tables. The changes for conventional DML changes are stored in the materialized view log associated with the master table. The changes for direct-path INSERT operations are stored in the direct loader log.
If you specify REFRESH FAST, then the CREATE statement will fail unless materialized view logs already exist for the materialized view master tables. Oracle Database creates the direct loader log automatically when a direct-path INSERT takes place. No user intervention is needed.
For both conventional DML changes and for direct-path INSERT operations, other conditions may restrict the eligibility of a materialized view for fast refresh.
指定FAST以指示增量刷新方法,该方法根据主表发生的更改来执行刷新。 常规DML更改的更改存储在与主表相关联的物化视图日志中。 直接路径INSERT操作的更改存储在直接加载程序日志中。
如果您指定了REFRESH FAST,则CREATE语句将失败,除非物化视图主表已存在实例化视图日志。 当直接路径INSERT发生时,Oracle数据库会自动创建直接加载程序日志。 不需要用户干预。
对于常规DML更改和直接路径INSERT操作,其他条件可能会限制实体化视图的快速刷新的资格。

Materialized views are not eligible for fast refresh if the defining query contains an analytic function.
如果定义查询包含分析函数,物化视图不符合快速刷新的资格。

See Also:

    Oracle Database Advanced Replication for restrictions on fast refresh in replication environments

    Oracle Database Data Warehousing Guide for restrictions on fast refresh in data warehousing environments

    The EXPLAIN_MVIEW procedure of the DBMS_MVIEW package for help diagnosing problems with fast refresh and the TUNE_MVIEW procedure of the DBMS_MVIEW package correction of fast refresh problems

    "Analytic Functions"

    "Creating a Fast Refreshable Materialized View: Example"

COMPLETE Clause

Specify COMPLETE to indicate the complete refresh method, which is implemented by executing the defining query of the materialized view. If you request a complete refresh, then Oracle Database performs a complete refresh even if a fast refresh is possible.
指定COMPLETE以指示完整的刷新方法,该方法通过执行物化视图的定义查询来实现。 如果您要求完全刷新,则即使可以快速刷新,Oracle数据库也会执行完全刷新

FORCE Clause

Specify FORCE to indicate that when a refresh occurs, Oracle Database will perform a fast refresh if one is possible or a complete refresh if fast refresh is not possible. If you do not specify a refresh method (FAST, COMPLETE, or FORCE), then FORCE is the default.  ON COMMIT Clause
Specify ON COMMIT to indicate that a fast refresh is to occur whenever the database commits a transaction that operates on a master table of the materialized view. This clause may increase the time taken to complete the commit, because the database performs the refresh operation as part of the commit process.
You cannot specify both ON COMMIT and ON DEMAND. If you specify ON COMMIT, then you cannot also specify START WITH or NEXT.
指定FORCE指示当刷新发生时,Oracle数据库将执行快速刷新(如果有可能)或完全刷新,如果不能快速刷新。 如果不指定刷新方法(FAST,COMPLETE或FORCE),则FORCE是默认值。 关于COMMIT条款
指定ON COMMIT指示每当数据库提交在实例化视图的主表上操作的事务时,将进行快速刷新。 此子句可能会增加完成提交所需的时间,因为数据库作为提交过程的一部分执行刷新操作。
您不能同时指定ON COMMIT和ON DEMAND。 如果指定ON COMMIT,则不能同时指定START WITH或NE

Restrictions on Refreshing ON COMMIT:刷新ON COMMIT的限制

    This clause is not supported for materialized views containing object types or Oracle-supplied types.

    This clause is not supported for materialized views with remote tables.

    If you specify this clause, then you cannot subsequently execute a distributed transaction on any master table of this materialized view. For example, you cannot insert into the master by selecting from a remote table. The ON DEMAND clause does not impose this restriction on subsequent distributed transactions on master tables.

ON DEMAND Clause

Specify ON DEMAND to indicate that database will not refresh the materialized view unless the user manually launches a refresh through one of the three DBMS_MVIEW refresh procedures.
You cannot specify both ON COMMIT and ON DEMAND. If you omit both ON COMMIT and ON DEMAND, then ON DEMAND is the default. You can override this default setting by specifying the START WITH or NEXT clauses, either in the same CREATE MATERIALIZED VIEW statement or a subsequent ALTER MATERIALIZED VIEW statement.
START WITH and NEXT take precedence over ON DEMAND. Therefore, in most circumstances it is not meaningful to specify ON DEMAND when you have specified START WITH or NEXT.
指定ON DEMAND指示数据库不会刷新物化视图,除非用户通过3个DBMS_MVIEW刷新过程之一手动启动刷新。
您不能同时指定ON COMMIT和ON DEMAND。 如果您省略ON COMMIT和ON DEMAND,则ON DEMAND是默认值。 您可以通过在相同的CREATE MATERIALIZED VIEW语句或后续的ALTER MATERIALIZED VIEW语句中指定START WITH或NEXT子句来覆盖此默认设置。
START WITH和NEXT优先于ON DEMAND。 因此,在大多数情况下,指定START WITH或NEXT时指定ON DEMAND是没有意义的。

See Also:

    Oracle Database PL/SQL Packages and Types Reference for information on these procedures

    Oracle Database Data Warehousing Guide on the types of materialized views you can create by specifying REFRESH ON DEMAND

START WITH Clause

Specify a datetime expression for the first automatic refresh time.
为第一个自动刷新时间指定一个日期时间表达式。

NEXT Clause

Specify a datetime expression for calculating the interval between automatic refreshes.
Both the START WITH and NEXT values must evaluate to a time in the future. If you omit the START WITH value, then the database determines the first automatic refresh time by evaluating the NEXT expression with respect to the creation time of the materialized view. If you specify a START WITH value but omit the NEXT value, then the database refreshes the materialized view only once. If you omit both the START WITH and NEXT values, or if you omit the create_mv_refresh entirely, then the database does not automatically refresh the materialized view.
指定一个日期时间表达式来计算自动刷新之间的时间间隔。
START WITH和NEXT值都必须在将来评估。 如果省略START WITH值,那么数据库通过评估与物化视图的创建时间相关的NEXT表达式来确定第一个自动刷新时间。 如果指定了START WITH值,但省略了NEXT值,则数据库仅刷新一次实例化视图。 如果您省略了START WITH和NEXT值,或者如果完全忽略create_mv_refresh,那么数据库不会自动刷新物化视图。

WITH PRIMARY KEY Clause

Specify WITH PRIMARY KEY to create a primary key materialized view. This is the default and should be used in all cases except those described for WITH ROWID. Primary key materialized views allow materialized view master tables to be reorganized without affecting the eligibility of the materialized view for fast refresh. The master table must contain an enabled primary key constraint, and the defining query of the materialized view must specify all of the primary key columns directly. In the defining query, the primary key columns cannot be specified as the argument to a function such as UPPER.
Restriction on Primary Key Materialized Views You cannot specify this clause for an object materialized view. Oracle Database implicitly refreshes objects materialized WITH OBJECT ID.
指定WITH PRIMARY KEY来创建一个主键物化视图。 这是默认值,应该在所有情况下使用,除了WITH ROWID描述的情况。 主键物化视图允许重构物化视图主表,而不影响物化视图的资格以进行快速刷新。 主表必须包含启用的主键约束,而物化视图的定义查询必须直接指定所有主键列。 在定义查询中,主键列不能被指定为函数的参数,如UPPER。
主键实例化视图的限制不能为对象实例化视图指定此子句。  Oracle数据库隐式刷新使用OBJECT ID实体化的对象

 See Also:
Oracle Database Advanced Replication for detailed information about primary key materialized views and "Creating Primary Key Materialized Views: Example"

WITH ROWID Clause

Specify WITH ROWID to create a rowid materialized view. Rowid materialized views are useful if the materialized view does not include all primary key columns of the master tables. Rowid materialized views must be based on a single table and cannot contain any of the following:
指定WITH ROWID来创建一个rowid物化视图。 如果实例化视图不包含主表的所有主键列,则Rowid实例化视图非常有用。  Rowid实体化视图必须基于一个表,并且不能包含以下任何一个:
    Distinct or aggregate functions

    GROUP BY or CONNECT BY clauses

    Subqueries

    Joins

    Set operations

The WITH ROWID clause has no effect if there are multiple master tables in the defining query.

Rowid materialized views are not eligible for fast refresh after a master table reorganization until a complete refresh has been performed.

Restriction on Rowid Materialized Views You cannot specify this clause for an object materialized view. Oracle Database implicitly refreshes objects materialized WITH OBJECT ID.

See Also:
"Creating Materialized Aggregate Views: Example" and "Creating Rowid Materialized Views: Example"

USING ROLLBACK SEGMENT Clause

This clause is not valid if your database is in automatic undo mode, because in that mode Oracle Database uses undo tablespaces instead of rollback segments. Oracle strongly recommends that you use automatic undo mode. This clause is supported for backward compatibility with replication environments containing older versions of Oracle Database that still use rollback segments.
如果数据库处于自动撤消模式,则此子句无效,因为在该模式下,Oracle数据库将使用撤消表空间而不是回滚段。  Oracle强烈建议您使用自动撤消模式。 此子句支持与包含仍旧使用回滚段的旧版Oracle数据库的复制环境的向后兼容性。

For rollback_segment, specify the remote rollback segment to be used during materialized view refresh.

DEFAULT DEFAULT specifies that Oracle Database will choose automatically which rollback segment to use. If you specify DEFAULT, then you cannot specify rollback_segment. DEFAULT is most useful when modifying, rather than creating, a materialized view.

See Also:
ALTER MATERIALIZED VIEW

MASTER MASTER specifies the remote rollback segment to be used at the remote master site for the individual materialized view.

LOCAL LOCAL specifies the remote rollback segment to be used for the local refresh group that contains the materialized view. This is the default.

See Also:
Oracle Database Advanced Replication for information on specifying the local materialized view rollback segment using the DBMS_REFRESH package

If you omit rollback_segment, then the database automatically chooses the rollback segment to be used. One master rollback segment is stored for each materialized view and is validated during materialized view creation and refresh. If the materialized view is complex, then the database ignores any master rollback segment you specify.

USING ... CONSTRAINTS Clause

The USING ... CONSTRAINTS clause lets Oracle Database choose more rewrite options during the refresh operation, resulting in more efficient refresh execution. The clause lets Oracle Database use unenforced constraints, such as dimension relationships or constraints in the RELY state, rather than relying only on enforced constraints during the refresh operation.

The USING TRUSTED CONSTRAINTS clause enables you to create a materialized view on top of a table that has a non-NULL Virtual Private Database (VPD) policy on it. In this case, ensure that the materialized view behaves correctly. Materialized view results are computed based on the rows and columns filtered by VPD policy. Therefore, you must coordinate the materialized view definition with the VPD policy to ensure the correct results. Without the USING TRUSTED CONSTRAINTS clause, any VPD policy on a master table will prevent a materialized view from being created.

Caution:
The USING TRUSTED CONSTRAINTS clause lets Oracle Database use dimension and constraint information that has been declared trustworthy by the database administrator but that has not been validated by the database. If the dimension and constraint information is valid, then performance may improve. However, if this information is invalid, then the refresh procedure may corrupt the materialized view even though it returns a success status.

If you omit this clause, then the default is USING ENFORCED CONSTRAINTS.

NEVER REFRESH Clause

Specify NEVER REFRESH to prevent the materialized view from being refreshed with any Oracle Database refresh mechanism or packaged procedure. Oracle Database will ignore any REFRESH statement on the materialized view issued from such a procedure. To reverse this clause, you must issue an ALTER MATERIALIZED VIEW ... REFRESH statement. 
指定"永不刷新"以防止使用任何Oracle数据库刷新机制或打包过程刷新物化视图。  Oracle数据库将忽略从此过程发出的物化视图上的任何REFRESH语句。 要反转这个子句,你必须发出一个ALTER MATERIALIZED VIEW ... REFRESH语句。  

CREATE MATERIALIZED VIEW LOG :

CREATE MATERIALIZED VIEW LOG ON [ schema. ] table
  [ physical_attributes_clause
  | TABLESPACE tablespace
  | logging_clause
  | { CACHE | NOCACHE }
  ]...
  [ parallel_clause ]
  [ table_partitioning_clauses ]
  [ WITH { OBJECT ID | PRIMARY KEY | ROWID | SEQUENCE | COMMIT SCN | (column [, column ]...)
         }
           [ { , OBJECT ID | , PRIMARY KEY | , ROWID | , SEQUENCE | , COMMIT SCN | (column [, column ]...)
             }
           ]...
    [ new_values_clause ]
  ] [ mv_log_purge_clause ] 
;

Oracle 物化视图 说明:

http://blog.csdn.net/tianlesoftware/article/details/4713553

物化视图详解--介绍、创建方法、例子:


http://blog.sina.com.cn/s/blog_5b2470430100ek3o.html

实验1:建立hr用户下的jobs表的基于fast refresh的物化视图:
[oracle@wang ~]$ sqlplus hr/hr;

SQL*Plus: Release 11.2.0.4.0 Production on Fri Nov 3 15:50:02 2017

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> show user;
USER is "HR"
SQL> 
SQL> create materialized view mv_jobs refresh fast  FOR UPDATE as select * from jobs;
create materialized view mv_jobs refresh fast  FOR UPDATE as select * from jobs
                                                                           *
ERROR at line 1:
ORA-01031: insufficient privileges

--报错,进行授权,如下:
SQL> show user;     
USER is "SYS"
SQL> 
SQL>        
SQL> grant CREATE MATERIALIZED VIEW to hr;

Grant succeeded.

--再次执行

SQL> create materialized view mv_jobs refresh fast  FOR UPDATE as select * from jobs;
create materialized view mv_jobs refresh fast  FOR UPDATE as select * from jobs
                                                                           *
ERROR at line 1:
ORA-23413: table "HR"."JOBS" does not have a materialized view log

--报错,应为基于refresh fast的物化视图必须先建立物化视图日志,如下:
   
SQL> create materialized view log on jobs purge repeat interval '5' day;

Materialized view log created.

--再次执行:
SQL>  create materialized view mv_jobs refresh fast  FOR UPDATE as select * from jobs;

Materialized view created.

--查看验证:
SQL> select * from mv_jobs;

JOB_ID     JOB_TITLE                           MIN_SALARY MAX_SALARY
---------- ----------------------------------- ---------- ----------
AD_PRES    President                                20080      40000
AD_VP      Administration Vice President            15000      30000
AD_ASST    Administration Assistant                  3000       6000
FI_MGR     Finance Manager                           8200      16000
FI_ACCOUNT Accountant                                4200       9000
AC_MGR     Accounting Manager                        8200      16000
AC_ACCOUNT Public Accountant                         4200       9000
SA_MAN     Sales Manager                            10000      20080
SA_REP     Sales Representative                      6000      12008
PU_MAN     Purchasing Manager                        8000      15000
PU_CLERK   Purchasing Clerk                          2500       5500

JOB_ID     JOB_TITLE                           MIN_SALARY MAX_SALARY
---------- ----------------------------------- ---------- ----------
ST_MAN     Stock Manager                             5500       8500
ST_CLERK   Stock Clerk                               2008       5000
SH_CLERK   Shipping Clerk                            2500       5500
IT_PROG    Programmer                                4000      10000
MK_MAN     Marketing Manager                         9000      15000
MK_REP     Marketing Representative                  4000       9000
HR_REP     Human Resources Representative            4000       9000
PR_REP     Public Relations Representative           4500      10500

19 rows selected.

SQL> select * from jobs;

JOB_ID     JOB_TITLE                           MIN_SALARY MAX_SALARY
---------- ----------------------------------- ---------- ----------
AD_PRES    President                                20080      40000
AD_VP      Administration Vice President            15000      30000
AD_ASST    Administration Assistant                  3000       6000
FI_MGR     Finance Manager                           8200      16000
FI_ACCOUNT Accountant                                4200       9000
AC_MGR     Accounting Manager                        8200      16000
AC_ACCOUNT Public Accountant                         4200       9000
SA_MAN     Sales Manager                            10000      20080
SA_REP     Sales Representative                      6000      12008
PU_MAN     Purchasing Manager                        8000      15000
PU_CLERK   Purchasing Clerk                          2500       5500

JOB_ID     JOB_TITLE                           MIN_SALARY MAX_SALARY
---------- ----------------------------------- ---------- ----------
ST_MAN     Stock Manager                             5500       8500
ST_CLERK   Stock Clerk                               2008       5000
SH_CLERK   Shipping Clerk                            2500       5500
IT_PROG    Programmer                                4000      10000
MK_MAN     Marketing Manager                         9000      15000
MK_REP     Marketing Representative                  4000       9000
HR_REP     Human Resources Representative            4000       9000
PR_REP     Public Relations Representative           4500      10500

19 rows selected.

SQL> 
 
--验证,往jobs插入数据:
SQL> insert into jobs values('aa','bb',5000,8000);

1 row created.

SQL> commit;

Commit complete.

SQL> select * from jobs;

JOB_ID     JOB_TITLE                           MIN_SALARY MAX_SALARY
---------- ----------------------------------- ---------- ----------
aa         bb                                        5000       8000
AD_PRES    President                                20080      40000
AD_VP      Administration Vice President            15000      30000
AD_ASST    Administration Assistant                  3000       6000
FI_MGR     Finance Manager                           8200      16000
FI_ACCOUNT Accountant                                4200       9000
AC_MGR     Accounting Manager                        8200      16000
AC_ACCOUNT Public Accountant                         4200       9000
SA_MAN     Sales Manager                            10000      20080
SA_REP     Sales Representative                      6000      12008
PU_MAN     Purchasing Manager                        8000      15000

JOB_ID     JOB_TITLE                           MIN_SALARY MAX_SALARY
---------- ----------------------------------- ---------- ----------
PU_CLERK   Purchasing Clerk                          2500       5500
ST_MAN     Stock Manager                             5500       8500
ST_CLERK   Stock Clerk                               2008       5000
SH_CLERK   Shipping Clerk                            2500       5500
IT_PROG    Programmer                                4000      10000
MK_MAN     Marketing Manager                         9000      15000
MK_REP     Marketing Representative                  4000       9000
HR_REP     Human Resources Representative            4000       9000
PR_REP     Public Relations Representative           4500      10500

20 rows selected.

SQL> select * from mv_jobs;

JOB_ID     JOB_TITLE                           MIN_SALARY MAX_SALARY
---------- ----------------------------------- ---------- ----------
AD_PRES    President                                20080      40000
AD_VP      Administration Vice President            15000      30000
AD_ASST    Administration Assistant                  3000       6000
FI_MGR     Finance Manager                           8200      16000
FI_ACCOUNT Accountant                                4200       9000
AC_MGR     Accounting Manager                        8200      16000
AC_ACCOUNT Public Accountant                         4200       9000
SA_MAN     Sales Manager                            10000      20080
SA_REP     Sales Representative                      6000      12008
PU_MAN     Purchasing Manager                        8000      15000
PU_CLERK   Purchasing Clerk                          2500       5500

JOB_ID     JOB_TITLE                           MIN_SALARY MAX_SALARY
---------- ----------------------------------- ---------- ----------
ST_MAN     Stock Manager                             5500       8500
ST_CLERK   Stock Clerk                               2008       5000
SH_CLERK   Shipping Clerk                            2500       5500
IT_PROG    Programmer                                4000      10000
MK_MAN     Marketing Manager                         9000      15000
MK_REP     Marketing Representative                  4000       9000
HR_REP     Human Resources Representative            4000       9000
PR_REP     Public Relations Representative           4500      10500

19 rows selected.

查询视图mv_jobs并为更新,因为如果在创建物化视图时不加on commit/on demand,默认是on demand:
解决1.You can override this default setting by specifying the START WITH or NEXT clauses, either in the same CREATE MATERIALIZED VIEW statement or a subsequent ALTER MATERIALIZED VIEW statement.
    2.使用dbms_mview.refresh 手工刷新 3.使用dbms_refresh.refresh 过程来批量刷新MV 如下:
SQL> alter materialized view mv_jobs refresh fast on demand  start with sysdate;

Materialized view altered.

SQL> 
SQL> select * from mv_jobs;

JOB_ID     JOB_TITLE                           MIN_SALARY MAX_SALARY
---------- ----------------------------------- ---------- ----------
AD_PRES    President                                20080      40000
AD_VP      Administration Vice President            15000      30000
AD_ASST    Administration Assistant                  3000       6000
FI_MGR     Finance Manager                           8200      16000
FI_ACCOUNT Accountant                                4200       9000
AC_MGR     Accounting Manager                        8200      16000
AC_ACCOUNT Public Accountant                         4200       9000
SA_MAN     Sales Manager                            10000      20080
SA_REP     Sales Representative                      6000      12008
PU_MAN     Purchasing Manager                        8000      15000
PU_CLERK   Purchasing Clerk                          2500       5500

JOB_ID     JOB_TITLE                           MIN_SALARY MAX_SALARY
---------- ----------------------------------- ---------- ----------
ST_MAN     Stock Manager                             5500       8500
ST_CLERK   Stock Clerk                               2008       5000
SH_CLERK   Shipping Clerk                            2500       5500
IT_PROG    Programmer                                4000      10000
MK_MAN     Marketing Manager                         9000      15000
MK_REP     Marketing Representative                  4000       9000
HR_REP     Human Resources Representative            4000       9000
PR_REP     Public Relations Representative           4500      10500
aa         bb                                        5000       8000

20 rows selected.

SQL> 

查看更新完毕!!!

--查看物化视图日志:
SQL> desc mlog$_jobs
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 JOB_ID                                             VARCHAR2(10)
 SNAPTIME$$                                         DATE
 DMLTYPE$$                                          VARCHAR2(1)
 OLD_NEW$$                                          VARCHAR2(1)
 CHANGE_VECTOR$$                                    RAW(255)
 XID$$                                              NUMBER

SQL> 


SQL>  select * from mlog$_jobs;

JOB_ID     SNAPTIME$$   D O CHANGE_VECTOR$$           XID$$
---------- ------------ - - -------------------- ----------
aa         03-NOV-17    I N FE                   2.8148E+15

SQL> 


实验2:创建基于refresh complete 完全刷新的物化视图,如下:
SQL> create materialized view mv_departments refresh complete on demand start with sysdate with PRIMARY KEY FOR UPDATE as select * from student;

Materialized view created.

SQL> select * from student;

        ID NAME
---------- ------------------------
      1002 jimmy

SQL> select * from mv_departments;

        ID NAME
---------- ------------------------
      1002 jimmy

--插入数据验证

SQL> insert into student values(1003,'wang');

1 row created.

SQL> commit;

Commit complete.

SQL>  select * from student;

        ID NAME
---------- ------------------------
      1002 jimmy
      1003 wang

SQL> select * from mv_departments;

        ID NAME
---------- ------------------------
      1002 jimmy

由于创建物化视图时只指定了start with,没有指定next date,所以只刷新一次,解决手工刷新,如下:

SQL> EXEC DBMS_MVIEW.REFRESH('mv_departments','C');

PL/SQL procedure successfully completed.

SQL> select * from mv_departments;

        ID NAME
---------- ------------------------
      1002 jimmy
      1003 wang




来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31397003/viewspace-2146802/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/31397003/viewspace-2146802/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值