行銷項目開工了,需要從EBS中提取表結構,並實現資料同步。
同步機制:每次同步時清空行銷table的所有資料,然後重新寫入。
日常同步:每周一次,EBS系統負載較小時同步(例如:每天淩晨2點)。
急需同步:EBS提供功能介面及按鈕,點擊按鈕自動執行同步(少用)。
可能存在問題:行銷系統的資料滯後...
在提取EBS表結構初,想當然地就直接按文檔說明在EBS中狂找對應的欄位名稱、資料類型...
類似於:
代碼
create table ERP_CONTACT
(
CONTACT_ID NUMBER(15),
CUST_ACCT_SITE_ID NUMBER(15) not null,
FIRST_NAME VARCHAR2(150),
LAST_NAME VARCHAR2(150),
COUNTRY_CODE VARCHAR2(10),
AREA_CODE VARCHAR2(10),
PHONE_NUMBER VARCHAR2(50),
PHONE_TYPE VARCHAR2(30),
MAIL_STOP VARCHAR2(60),
PHONE_STATUS VARCHAR2(30),
CONTACT_STATUS VARCHAR2(1),
CREATION_DATE DATE,
CREATED_BY NUMBER(15),
LAST_UPDATE_DATE DATE,
LAST_UPDATED_BY NUMBER(15)
)
但是之後asheng提醒,這樣表結構是搞出來了,但是下一次需要實現同步時候,是不是還是要再整理一遍?
實在是不想再一次去碰EBS的table,會瘋的...
那麼有幾件事情要做,首先是找到對應欄位的基表(非視圖,EBS視圖過於龐大),然後找到基表之間的關係,需要注意table的一些必要限制條件。 如:
create table ERP_CONTACT
as
select contact.contact_id,
addr.cust_acct_site_id,
contact.first_name,
contact.last_name,
phone.country_code,
phone.area_code,
phone.phone_number,
phone.phone_type,
contact.mail_stop,
phone.status phone_status
contact.status contact_status,
contact.creation_date,
contact.created_by,
contact.last_update_date,
contact.last_updated_by
from hz_cust_acct_sites_all addr,
ar_phones_v phone,
(select acct_role.cust_account_role_id contact_id,
party.person_first_name first_name,
party.person_last_name last_name,
org_cont.mail_stop,
acct_role.status,
acct_role.creation_date,
acct_role.created_by,
acct_role.last_update_date,
acct_role.last_updated_by,
acct_role.cust_account_id,
acct_role.cust_acct_site_id,
rel_party.party_id
from hz_contact_points cont_point,
hz_cust_account_roles acct_role,
hz_parties party,
hz_parties rel_party,
hz_relationships rel,
hz_org_contacts org_cont,
hz_cust_accounts role_acct,
hz_contact_restrictions cont_res,
hz_person_language per_lang
where acct_role.party_id = rel.party_id
and acct_role.role_type = 'CONTACT'
and org_cont.party_relationship_id = rel.relationship_id
and rel.subject_id = party.party_id
and rel_party.party_id = rel.party_id
and cont_point.owner_table_id(+) = rel_party.party_id
and cont_point.contact_point_type(+) = 'EMAIL'
and cont_point.primary_flag(+) = 'Y'
and acct_role.cust_account_id = role_acct.cust_account_id
and role_acct.party_id = rel.object_id
and party.party_id = per_lang.party_id(+)
and per_lang.native_language(+) = 'Y'
and party.party_id = cont_res.subject_id(+)
and cont_res.subject_table(+) = 'HZ_PARTIES') contact
where addr.cust_account_id = contact.cust_account_id(+)
and addr.cust_acct_site_id = contact.cust_acct_site_id(+)
and contact.party_id = phone.owner_table_id(+);
這樣做的好處在於,一個是達到建立表結構的目的,資料類型也與EBS同步,另外當需要同步資料時,就只需要執行select語句就取得了所需要的資料。