您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
1.创建原表和物化视图日志
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插入一条数据,一提交t2即存在数据
SQL> insert into t1 values(1,'A'); 1 row created. SQL> commit; Commit complete. SQL> select * from t2; ID NAME ---------- ------------------------------ 1 A
4.ddl测试
通过测试我们发现物化视图不支持ddl语句
我们给t1添加一个列和rename一个列
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
发现数据没有过来,我们看一下物化视图的定义和状态
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
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。