现在需要把生产论坛 iis7站长之家中的部分数据同步到数据仓库中,考虑到成本和便捷性,采用定期刷新物化视图的方式同步数据。
l 在本地创建一个物化视图,存储远程数据表,当远程数据表有变化时,会定时刷新到物化视图中。
testrac =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.122)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.123)(PORT = 1521))
(SERVICE_NAME = jscn)
)
)
测试:
[oracle@testrac1 goldengate]$ sqlplus sys/sys@ testrac as sysdba
SQL> select count(*) from SYS.GV_$INSTANCE
语法:
create public database link dblink_nameconnect to username identified by passwd using 'tns_name'
说明:
dblink_name :是dblink名称
username:是远端的用户名
passwd:是远端的秘密
'tns_name' :是tnsnames.ora中的连接字符串名称
示例如下:
SQL> create public database link testrac connect to jscn identified by jscn using 'testrac';
SQL> select count(*) from SYS.GV_$INSTANCE@testrac;
COUNT(*)
----------
2
说明:
对于已定义主键的表,分别执行以下 sql:
create materialized view log on 表名 withprimary key;
对于未定义主键的表,分别执行以下 sql:
creatematerialized view log on 表名 with rowid;
使用sql语句:
select 'creatematerialized view log on '||table_name||' withprimary key;' fromuser_tables;
create materialized view log on thh with primary key;
--这两个没有主键,特殊对待
create materialized view log on USER_ORDER_INTE with rowid;
4.3.2 在目标用户上执行以下 sql,创建物化视图
创建物化视图语法如下:
create materialized view [view_name]
refresh [fast|complete|force] with [primaryid | rowid]
[
on [commit|demand] |
start with (start_time) next (next_time)
]
as
使用sql语句:
select 'create materializedview '||table_name||' refresh fast on demand as select * fromthh@testrac;' fromuser_tables;
create materialized view CONSIGNEE_ADDRESS refresh fast on demand as select * from thh@testrac;
create materialized view CUSTOMER refresh fast on demand as select * from thh@testrac;
定时任务放在每天凌晨3点执行任务。
BEGIN
LIST=> 'OMORDER,ORDERDETAIL,ORDERTRACER,THH,THH_SUB,VACCOUNTREASON,CONSIGNEE_ADDRESS,LOGISTICS_COMPANY,PRODUCT,PRODUCT_CATE_REL,PRODUCTCATEGORY,STORE,STORE_INFO,CUSTOMER,CUSTOMER_INFO,USER_ORDER_INTE,GIFT_CARDS,GIFT_CARDS_TYPE,GIFT_CARDS_LOG,PROMOTIONS_OFFERS,JOIN_PROMOTIONS,TEL_EMAIL_RECORD,dealcategory,YDORDER,YDORDERTRACER,PRODUCT_BRAND,THH_LOGS',
METHOD => 'F',
PARALLELISM => 1);
END;
更多Oracle相关信息见 专题页面