create table t1(id int,name varchar2(30)); Table created. SQL> alter table t..."/>
您好,登錄后才能下訂單哦!
1.創(chuàng)建原表和物化視圖日志
SQL> create table t1(id int,name varchar2(30)); Table created. SQL> alter table t1 add constraint pk_t1 primary key(id) using index; Table altered. SQL> create materialized view log on t1 with primary key; Materialized view log created.
SQL> create table t2 as select * from t1 where 1=2; Table created. SQL> create materialized view t2 on prebuilt table refresh fast on commit as select * from t1; Materialized view created.
3.簡單測試
在t1插入一條數(shù)據(jù),一提交t2即存在數(shù)據(jù)
SQL> insert into t1 values(1,'A'); 1 row created. SQL> commit; Commit complete. SQL> select * from t2; ID NAME ---------- ------------------------------ 1 A
4.ddl測試
通過測試我們發(fā)現(xiàn)物化視圖不支持ddl語句
我們給t1添加一個(gè)列和rename一個(gè)列
SQL> alter table t1 add ddl_test int; Table altered. SQL> alter table t1 rename column name to names; Table altered. SQL> select * from t2; ID NAME ---------- ------------------------------ 1 A 2 4 SQL> insert into t1 values(3,'x',1234); 1 row created. SQL> commit; Commit complete. SQL> select * from t1; ID NAMES DDL_TEST ---------- ------------------------------ ---------- 1 A 2 4 3 x1234 SQL> select * from t2; ID NAME ---------- ------------------------------ 1 A 2 4
發(fā)現(xiàn)數(shù)據(jù)沒有過來,我們看一下物化視圖的定義和狀態(tài)
SQL> select dbms_metadata.get_ddl('MATERIALIZED_VIEW','T2') from dual; DBMS_METADATA.GET_DDL('MATERIALIZED_VIEW','T2') -------------------------------------------------------------------------------- CREATE MATERIALIZED VIEW "SCOTT"."T2" ("ID", "NAME") ON PREBUILT TABLE WITH SQL> select staleness from user_mviews; STALENESS ------------------- COMPILATION_ERROR
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。