--1.create materialized view log on YWUSER.BIAUTOPRICEXOM with primary key; --在dblink远程表创建log
--1.在ods用户下创建表,删表空间,主键,添加lastmodifydate 默认系统时间,注释
create table BIAUTOPRICEXOM
(
autopricedemandno VARCHAR2(100) not null,
certino VARCHAR2(100),
riskcode VARCHAR2(4),
autopriceflag VARCHAR2(1),
autopricereason VARCHAR2(1000),
filedexp NUMBER(4,2),
targetlr NUMBER(8,4),
feerate NUMBER(8,4),
managementfeerate NUMBER(8,4),
profitrate NUMBER(8,4),
ccimrk VARCHAR2(1),
accidentrecordsr VARCHAR2(5),
accidentrecordsb VARCHAR2(5),
endorsementrater NUMBER(8,4),
endorsementrateb NUMBER(8,4),
premiumpercent NUMBER(8,4),
govdiscfloor NUMBER(10,6),
govdisctop NUMBER(10,6),
expdisc NUMBER(10,6),
customerno VARCHAR2(50),
uwdisc NUMBER(10,6),
comcostprem NUMBER(12,4),
ctpcostprem NUMBER(12,4),
entirecostdisc NUMBER(10,6),
entirefitdisc NUMBER(10,6),
entireexpfitdisc NUMBER(10,6),
entireuwfitdisc NUMBER(10,6),
vhlclassindex VARCHAR2(10),
companydiscfloor NUMBER(10,6),
entirebilldiscount NUMBER(10,6),
companydisctop NUMBER(10,6),
lastmodifydate date default sysdate
) tablespace ODS_DATA
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 64K
next 1M
minextents 1
maxextents unlimited
);
--2.在ods用户下改表名
ALTER TABLE BIAUTOPRICEXOM RENAME to YW_BIAUTOPRICEXOM;
--3.在ods用户下创建物化视图
CREATE MATERIALIZED VIEW YW_BIAUTOPRICEXOM ON PREBUILT TABLE REFRESH force ON DEMAND with primary key AS
SELECT
autopricedemandno ,
certino ,
riskcode ,
autopriceflag ,
autopricereason ,
filedexp ,
targetlr ,
feerate ,
managementfeerate ,
profitrate ,
ccimrk ,
accidentrecordsr ,
accidentrecordsb ,
endorsementrater ,
endorsementrateb ,
premiumpercent ,
govdiscfloor ,
govdisctop ,
expdisc ,
customerno ,
uwdisc ,
comcostprem ,
ctpcostprem ,
entirecostdisc ,
entirefitdisc ,
entireexpfitdisc ,
entireuwfitdisc ,
vhlclassindex ,
companydiscfloor ,
entirebilldiscount ,
companydisctop
FROM YWUSER.BIAUTOPRICEXOM@YWUSER;
--4.在ods触发器
CREATE OR REPLACE TRIGGER TG_YW_BIAUTOPRICEXOM
---进行更新操作时候
BEFORE UPDATE ON YW_BIAUTOPRICEXOM
---任何一行
FOR EACH ROW
BEGIN
----将修改时间插入datadate中
:NEW.LastModifyDate := SYSDATE;
END;
--5.全量刷新物化视图(C是全量,F是增量)
call dbms_mview.refresh('YW_BIAUTOPRICEXOM','C');
--6.创建主键,表空间
alter table YW_BIAUTOPRICEXOM
add constraint PK_YW_BIAUTOPRICEXOM primary key (AUTOPRICEDEMANDNO)
using index
tablespace ODS_IDX
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 64K
next 1M
minextents 1
maxextents unlimited
pctincrease 0
);
--7.核对数据
select count(0) from YW_BIAUTOPRICEXOM;
select count(0) from BIAUTOPRICEXOM@YWUSER;
--8.创建存储过程
create or replace procedure PRO_MV_REFRASH_YW is
begin
dbms_mview.refresh('YW_BIAUTOPRICEXOM','F');
end PRO_MV_REFRASH_YW;
--9.创建scheduler_job进行定时刷新
begin
sys.dbms_scheduler.create_job(job_name => 'ODS.JOB_MV_REFRASH_YW',
job_type => 'STORED_PROCEDURE',
job_action => 'PRO_MV_REFRASH_YW',
start_date => to_date('24-01-2017 00:00:00', 'dd-mm-yyyy hh24:mi:ss'),
repeat_interval => 'Freq=Daily;ByHour=00;ByMinute=05;BySecond=00',
end_date => to_date(null),
job_class => 'DEFAULT_JOB_CLASS',
enabled => true,
auto_drop => false,
comments => '每天增量刷新YW用户下的物化视图');
end;
/
整个过程完成!