使用 Oracle 数据库 10g内部的 ETL 基础架构
使用 Oracle 数据库 10g内部的 ETL 基础架构
http://www.oracle.com/technology/global/cn/obe/10gr2_db_single/bidw/etl2/etl2_otn.htm
--在关于Change Data Capture(一)中介绍了CDC的一些基本概念和类型。这篇文章主要是通过一个实际的例子来演示实现同步模式的CDC的基本步骤。
-- Create table
create table SALES
(
ID NUMBER,
PRODUCTID NUMBER,
PRICE NUMBER,
QUANTITY NUMBER
)
--url:http://www.ningoo.net/html/tag/cdc
--2.1.首先在source database创建一个用户作为发布者
create user cdcpub identified by cdcpub;
--2.2.授予相应的权限
grant execute_catalog_role to cdcpub;
grant select_catalog_role to cdcpub;
grant create table to cdcpub;
grant create session to cdcpub;
grant dba to cdcpub;
grant execute on dbms_cdc_publish to cdcpub; --出错
--3.1
alter system set java_pool_size=48M;
--4.1
grant all on system.sales to cdcpub; --出错
--4.2
begin
dbms_cdc_publish.create_change_set(
change_set_name =>'test_cdc',
description =>'change set for ning.sales',
change_source_name =>'SYNC_SOURCE');
end;
--4.3
begin
dbms_cdc_publish.create_change_table(
owner =>'cdcpub',
change_table_name=>'sales_ct',
change_set_name=>'test_cdc',
source_schema=>'system',
source_table=>'sales',
column_type_list=>'id int,productid int,price number(10,2),quantity int',
capture_values=>'both',
rs_id=>'y',
row_id=>'n',
user_id=>'n',
timestamp=>'n',
object_id=>'n',
source_colmap=>'y',
target_colmap=>'y',
options_string=>'tablespace users',
ddl_markers=>'n');--Oracle11 新添加参数
end;
--5.1
create user cdcsub identified by cdcsub;
grant create session to cdcsub;
grant create table to cdcsub;
grant select on cdcpub.sales_ct to cdcsub;
--5.3.创建订阅
begin
dbms_cdc_subscribe.create_subscription(
change_set_name=>'test_cdc',
description=>'change data for sales',
subscription_name=>'sales_sub');
end;
--5.4.订阅具体的source table和column
begin
dbms_cdc_subscribe.subscribe(
subscription_name=>'sales_sub',
source_schema=>'system',
source_table=>'SALES',
column_list=>'id,productid,price,quantity',
subscriber_view=>'TCDC_VIEW_SALES');
--subscriber_view=>'sales_view');
end;
--5.5.激活订阅 不管订阅包含一个source table还是多个,只需要执行一次激活即可。
begin
dbms_cdc_subscribe.activate_subscription(
subscription_name=>'SALES_SUB');
end;
--5.6.扩展订阅窗口 在源表数据变化后,变化的数据在订阅端需要执行extend_window后才能看见
begin
dbms_cdc_subscribe.extend_window(
subscription_name=>'SALES_SUB');
en
http://www.oracle.com/technology/global/cn/obe/10gr2_db_single/bidw/etl2/etl2_otn.htm
--在关于Change Data Capture(一)中介绍了CDC的一些基本概念和类型。这篇文章主要是通过一个实际的例子来演示实现同步模式的CDC的基本步骤。
-- Create table
create table SALES
(
)
--url:http://www.ningoo.net/html/tag/cdc
--2.1.首先在source database创建一个用户作为发布者
create user cdcpub identified by cdcpub;
--2.2.授予相应的权限
grant execute_catalog_role to cdcpub;
grant select_catalog_role to cdcpub;
grant create table to cdcpub;
grant create session to cdcpub;
grant dba to cdcpub;
grant execute on dbms_cdc_publish to cdcpub; --出错
--3.1
alter system set java_pool_size=48M;
--4.1
grant all on system.sales to cdcpub;
--4.2
begin
dbms_cdc_publish.create_change_set(
change_set_name =>'test_cdc',
description =>'change set for ning.sales',
change_source_name =>'SYNC_SOURCE');
end;
--4.3
begin
dbms_cdc_publish.create_change_table(
owner =>'cdcpub',
change_table_name=>'sales_ct',
change_set_name=>'test_cdc',
source_schema=>'system',
source_table=>'sales',
column_type_list=>'id int,productid int,price number(10,2),quantity int',
capture_values=>'both',
rs_id=>'y',
row_id=>'n',
user_id=>'n',
timestamp=>'n',
object_id=>'n',
source_colmap=>'y',
target_colmap=>'y',
options_string=>'tablespace users',
ddl_markers=>'n');--Oracle11 新添加参数
end;
--5.1
create user cdcsub identified by cdcsub;
grant create session to cdcsub;
grant create table to cdcsub;
grant select on cdcpub.sales_ct to cdcsub;
--5.3.创建订阅
begin
dbms_cdc_subscribe.create_subscription(
change_set_name=>'test_cdc',
description=>'change data for sales',
subscription_name=>'sales_sub');
end;
--5.4.订阅具体的source table和column
begin
dbms_cdc_subscribe.subscribe(
subscription_name=>'sales_sub',
source_schema=>'system',
source_table=>'SALES',
column_list=>'id,productid,price,quantity',
subscriber_view=>'TCDC_VIEW_SALES');
--subscriber_view=>'sales_view');
end;
--5.5.激活订阅 不管订阅包含一个source table还是多个,只需要执行一次激活即可。
begin
dbms_cdc_subscribe.activate_subscription(
subscription_name=>'SALES_SUB');
end;
--5.6.扩展订阅窗口
begin
dbms_cdc_subscribe.extend_window(
subscription_name=>'SALES_SUB');
en