创建物化视图

/*
下面是关于创建物化视图的小例子,首先建了两个表(数据自已填充吧),
接下来就是创建两个物化视图.
*/
-- Create table
create table TEST_M1
(
  ID   VARCHAR2(50) not null,
  NAME VARCHAR2(50)
)
tablespace GS12315_TBS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64
    minextents 1
    maxextents unlimited
  );
-- Add comments to the table
comment on table TEST_M1
  is '物化视图测试';
-- Create/Recreate primary, unique and foreign key constraints
alter table TEST_M1
  add constraint PK_TEST_M1 primary key (ID)
  using index
  tablespace GS12315_TBS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
------------- 
-- Create table
create table TEST_M2
(
  ID     VARCHAR2(50) not null,
  ADRESS VARCHAR2(50)
)
tablespace GS12315_TBS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64
    minextents 1
    maxextents unlimited
  );
-- Add comments to the table
comment on table TEST_M2
  is '物化视图测试';
-- Create/Recreate primary, unique and foreign key constraints
alter table TEST_M2
  add constraint PK_TEST_M2 primary key (ID)
  using index
  tablespace GS12315_TBS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );

--创建物化视图表日志      
Create materialized view log on  test_m1 WITH rowid;----test_m1为表名
Create materialized view log on  test_m2 WITH rowid;----test_m2为表名 

--删除日志
drop materialized view log on test_m1;  
drop materialized view log on test_m2;  

--创建物化视图语句(在基本提交的时候刷新物化视图):
Create materialized view MV_TEST_COMMIT
Build immediate
Refresh fast
On commit
With rowid
as
Select m1.id,m1.name,m2.ADRESS,m1.rowid m1rowid,m2.rowid m2rowid
from test_m1 m1,test_m2 m2
where m1.id = m2.id;  
--删除物化视图
drop materialized view MV_TEST_COMMIT;
--查询物化视图
select * from MV_TEST_COMMIT
--创建物化视图语句(每隔一分钟物化视图更新一次数据):
Create materialized view MV_TEST_DEMAND
Build immediate
REFRESH FAST ON demand
START WITH sysdate+1/(24*60) NEXT sysdate+1/(24*60)
WITH rowid
DISABLE QUERY REWRITE
as
Select m1.id,m1.name,m2.ADRESS,m1.rowid m1rowid,m2.rowid m2rowid
from test_m1 m1,test_m2 m2
where m1.id = m2.id;  
--删除物化视图
drop materialized view MV_TEST_DEMAND;   
--查询物化视图
select * from MV_TEST_DEMAND

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值