The following lines contain the word 'select', 'insert', 'update' or 'delete':
CURSOR app_id IS select distinct(dict_application_id) from hz_merge_dictionary
where parent_entity_name='HZ_PARTIES'
and nvl(validate_purge_flag,'Y') <> 'N'; --5125968
select decode(entity_name,'HZ_PARTY_RELATIONSHIPS','HZ_RELATIONSHIPS',entity_name) entity_name, fk_column_name, decode(entity_name,'HZ_PARTY_RELATIONSHIPS','RELATIONSHIP_ID',pk_column_name) pk_column_name,
decode(entity_name,'HZ_PARTY_RELATIONSHIPS', join_clause || ' AND subject_table_name = ''HZ_PARTIES'' AND object_table_name = ''HZ_PARTIES''
AND directional_flag = ''F''', join_clause) join_clause, parent_entity_name,fk_data_type
from hz_merge_dictionary where parent_entity_name like 'HZ_%' and dict_application_id = app_id
and fk_column_name IS NOT NULL and entity_name not in ('AS_CHANGED_ACCOUNTS_ALL','POS_PARTIES_V','POS_PARTY_SITES_V','WSH_LOCATION_OWNERS','ZX_PARTY_TAX_PROFILE','CE_BANKS_MERGE_V','CE_BANK_BRANCHES_MERGE_V','WSH_SUPPLIER_SF_SITES_V')
and nvl(validate_purge_flag,'Y') <> 'N'; --5125968
select decode(entity_name,'HZ_PARTY_RELATIONSHIPS','HZ_RELATIONSHIPS',entity_name) entity_name, fk_column_name,
decode(entity_name,'HZ_PARTY_RELATIONSHIPS','RELATIONSHIP_ID',pk_column_name) pk_column_name,
decode(entity_name,'HZ_PARTY_RELATIONSHIPS', join_clause || ' AND subject_table_name = ''HZ_PARTIES'' AND object_table_name = ''HZ_PARTIES''
AND directional_flag = ''F''', join_clause) join_clause,
parent_entity_name, fk_data_type
from hz_merge_dictionary where parent_entity_name like 'HZ_%' and dict_application_id = app_id
and entity_name in('HZ_CUST_ACCOUNTS','HZ_CUST_ACCT_SITES_ALL','HZ_CUSTOMER_PROFILES') OR
(entity_name ='HZ_PARTY_RELATIONSHIPS' and fk_column_name<>'PARTY_ID') OR
(entity_name ='HZ_ORGANIZATION_PROFILES' and fk_column_name ='DISPLAYED_DUNS_PARTY_ID');
stmt1 varchar2(31000):= 'delete from hz_purge_gt temp where ';
stmt2 varchar2(31000):= 'delete /*+ parallel(temp) */ from hz_purge_gt temp where ';
HZ_GEN_PLSQL.ADD_LINE('select party_id from hz_purge_gt;');
HZ_GEN_PLSQL.add_line('delete from hz_application_trans_gt; ');
delete_template(e1, fk1, pk1, j1, pe1, fk_data_typ1, 'TRUE', s2, cnt);
delete_template(e1, fk1, pk1, j1, pe1, fk_data_typ1,'TRUE', s2,cnt);
HZ_GEN_PLSQL.ADD_LINE('--delete and insert records into hz_purge_gt for an application');
stmt3:= 'insert into hz_application_trans_gt(app_id,party_id) select '||appid||', temp.party_id from hz_purge_gt temp where ';
stmt1 := 'delete from hz_purge_gt temp where ';
stmt3 := 'insert into hz_application_trans_gt(app_id,party_id) select '||appid||', temp.party_id from hz_purge_gt temp where ';
delete_template(e1, fk1, pk1, j1, pe1, fk_data_typ1,'FALSE', s2,cnt);
stmt4 := 'insert into hz_application_trans_gt(app_id,party_id) select '||appid||', temp.party_id from hz_purge_gt temp ';
stmt5 := ' where not exists(select ''Y'' from hz_application_trans_gt appl where appl.app_id = '||appid||' and appl.party_id=temp.party_id) and ';
HZ_GEN_PLSQL.ADD_LINE('delete from hz_purge_gt temp where temp.party_id in (select appl.party_id from hz_application_trans_gt appl) ;');
insert_stmt varchar2(5000):= 'insert into hz_purge_gt(party_id) select party_id from hz_parties where party_type<>''NULL'' ';
delete_stmt varchar2(5000):= 'delete from hz_purge_gt ';
mergedict_update_date date;
select h.party_id, p.party_name from hz_purge_gt h, hz_parties p where h.party_id=p.party_id;
select to_date(timestamp,'YYYY-MM-DD:HH24:MI:SS') from sys.user_objects
where object_type='PACKAGE BODY' and status='VALID'and object_name='HZ_PURGE_GEN';
cursor dict_update_date is
select max(last_update_date) from hz_merge_dictionary;
select subset_sql, attributes_flag from hz_purge_batches where batch_id = to_number(batchid);
select count(*) from hz_purge_gt;
select distinct(app_id), party_id from hz_application_trans_gt;
select distinct(party_id) from hz_purge_gt;
open dict_update_date;
fetch dict_update_date into mergedict_update_date;
close dict_update_date;
/* Generate the body of the Package HZ_PURGE_GEN if last_update_date of hz_merge_dictionary
is greater than the package generation date*/
if (mergedict_update_date is null or time_stamp is null or mergedict_update_date>time_stamp) then
hz_purge.generate_body(p_init_msg_list, x_return_status, x_msg_count, x_msg_data);
insert_stmt := insert_stmt||' and '||where_clause;
execute immediate delete_stmt;
execute immediate insert_stmt;
/* Insert into the hz_purge_candidates table */
/* insert into hz_purge_candidates(BATCH_ID,CANDIDATE_PARTY_ID,PARTY_NAME,PARTY_NUMBER,ADDRESSES,PHONE_NUMBERS,COUNTRY,STATUS,CREATION_DATE,
LAST_UPDATE_LOGIN,LAST_UPDATE_DATE,LAST_UPDATED_BY,CREATED_BY)
select to_number(batchid), a.party_id, substr(a.party_name,1,250), a.party_number,
a.address1||','||a.city||','||a.state||','||a.country||' '||a.postal_code,
cp.PHONE_AREA_CODE||'-'||cp.PHONE_COUNTRY_CODE||'-'||cp.PHONE_NUMBER, a.country, 'IDENTIFIED',
sysdate, fnd_global.login_id, sysdate, fnd_global.user_id, fnd_global.user_id
from hz_parties a , hz_purge_gt temp, hz_contact_points cp where
temp.party_id = a.party_id and
cp.owner_table_id(+)=temp.party_id and
cp.contact_point_type(+)='PHONE' and
cp.owner_table_name(+)='HZ_PARTIES' and
cp.primary_flag(+)='Y';
insert into hz_purge_candidates(BATCH_ID,CANDIDATE_PARTY_ID,PARTY_NAME,PARTY_NUMBER,ADDRESSES,PHONE_NUMBERS,COUNTRY,STATUS,CREATION_DATE,
LAST_UPDATE_LOGIN,LAST_UPDATE_DATE,LAST_UPDATED_BY,CREATED_BY)
select to_number(batchid), pid, substr(a.party_name,1,250), a.party_number,
a.address1||','||a.city||','||a.state||','||a.country||' '||a.postal_code,
cp.PHONE_AREA_CODE||'-'||cp.PHONE_COUNTRY_CODE||'-'||cp.PHONE_NUMBER, a.country, 'IDENTIFIED',
sysdate, fnd_global.login_id, sysdate, fnd_global.user_id, fnd_global.user_id
from hz_parties a , hz_contact_points cp where
a.party_id = pid and
cp.owner_table_id(+)= a.party_id and
cp.contact_point_type(+)='PHONE' and
cp.owner_table_name(+)='HZ_PARTIES' and
cp.primary_flag(+)='Y';
update hz_purge_batches set num_candidates=num_parties, num_marked=num_parties, status='IDENTIFICATION_COMPLETE' where batch_id=to_number(batchid);
insert into hz_non_purge_candidates(BATCH_ID,CANDIDATE_PARTY_ID,APPL_ID,
PARTY_NAME,PARTY_NUMBER,ADDRESSES,PHONE_NUMBERS,COUNTRY,CREATION_DATE,
LAST_UPDATE_LOGIN,LAST_UPDATE_DATE,LAST_UPDATED_BY,CREATED_BY)
select to_number(batchid), p_id, app_id, substr(a.party_name,1,250), a.party_number,
null, null, null,
x_sysdate, fnd_global.login_id, sysdate, fnd_global.user_id, fnd_global.user_id
from hz_parties a where
a.party_id = p_id;
update hz_purge_batches set status='IDENTIFICATION_ERROR' where batch_id=to_number(batchid);
update hz_purge_batches set status='IDENTIFICATION_ERROR' where batch_id=to_number(batchid);
update hz_purge_batches set status='IDENTIFICATION_ERROR' where batch_id=to_number(batchid);
select count(*) from hz_application_trans_gt;
delete from hz_purge_gt;
insert into hz_purge_gt(party_id) select party_id from hz_parties where party_id=partyid;
select candidate_party_id, party_name from hz_purge_candidates where batch_id=batchid and status='IDENTIFIED';
DELETE from HZ_PARTY_USG_ASSIGNMENTS where PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=batchid and status='IDENTIFIED');
log(' HZ_PARTY_USG_ASSIGNMENTS : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
DELETE from HZ_ORGANIZATION_PROFILES where PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=batchid and status='IDENTIFIED');
log(' HZ_ORGANIZATION_PROFILES : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
execute immediate 'DELETE from HZ_CONTACT_PREFERENCES where CONTACT_LEVEL_TABLE_ID in
( select CONTACT_POINT_ID FROM HZ_CONTACT_POINTS WHERE OWNER_TABLE_ID in
(SELECT PARTY_SITE_ID FROM HZ_PARTY_SITES WHERE PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=:1 and status=''IDENTIFIED''))and OWNER_TABLE_NAME=''HZ_PARTY_SITES'')
and CONTACT_LEVEL_TABLE=''HZ_CONTACT_POINTS''' using batchid;
log(' HZ_CONTACT_PREFERENCES : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
execute immediate 'DELETE from HZ_STAGED_CONTACT_POINTS where CONTACT_POINT_ID in
( select CONTACT_POINT_ID FROM HZ_CONTACT_POINTS WHERE OWNER_TABLE_ID in
(SELECT PARTY_SITE_ID FROM HZ_PARTY_SITES WHERE PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=:1 and status=''IDENTIFIED'')) and OWNER_TABLE_NAME=''HZ_PARTY_SITES'')' using batchid;
log(' HZ_STAGED_CONTACT_POINTS : Deleted '||SQL%ROWCOUNT||' rows', conc_prg);
DELETE from HZ_CONTACT_POINTS where OWNER_TABLE_ID in
( select PARTY_SITE_ID FROM HZ_PARTY_SITES WHERE PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=batchid and status='IDENTIFIED')) and OWNER_TABLE_NAME='HZ_PARTY_SITES';
log(' HZ_CONTACT_POINTS : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
DELETE from HZ_ORG_CONTACT_ROLES where ORG_CONTACT_ID in
( select ORG_CONTACT_ID FROM HZ_ORG_CONTACTS WHERE PARTY_SITE_ID in (
SELECT PARTY_SITE_ID FROM HZ_PARTY_SITES WHERE PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=batchid and status='IDENTIFIED')));
log(' HZ_ORG_CONTACT_ROLES : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
execute immediate 'DELETE from HZ_STAGED_CONTACTS where ORG_CONTACT_ID in
( select ORG_CONTACT_ID FROM HZ_ORG_CONTACTS WHERE PARTY_SITE_ID in
(SELECT PARTY_SITE_ID FROM HZ_PARTY_SITES WHERE PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=:1 and status=''IDENTIFIED'')))' using batchid;
log(' HZ_STAGED_CONTACTS : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
DELETE from HZ_ORG_CONTACTS where PARTY_SITE_ID in
( select PARTY_SITE_ID FROM HZ_PARTY_SITES WHERE PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=batchid and status='IDENTIFIED'));
log(' HZ_ORG_CONTACTS : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
DELETE from HZ_PARTY_SITE_USES where PARTY_SITE_ID in
( select PARTY_SITE_ID FROM HZ_PARTY_SITES WHERE PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=batchid and status='IDENTIFIED'));
log(' HZ_PARTY_SITE_USES : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
execute immediate 'DELETE from HZ_CODE_ASSIGNMENTS where OWNER_TABLE_ID in
( select PARTY_SITE_ID FROM HZ_PARTY_SITES WHERE PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=:1 and status=''IDENTIFIED''))
and OWNER_TABLE_NAME=''HZ_PARTY_SITES''' using batchid;
log(' HZ_CODE_ASSIGNMENTS : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
execute immediate 'DELETE from HZ_CONTACT_PREFERENCES where CONTACT_LEVEL_TABLE_ID in
( select PARTY_SITE_ID FROM HZ_PARTY_SITES WHERE PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=:1 and status=''IDENTIFIED''))
and CONTACT_LEVEL_TABLE=''HZ_PARTY_SITES''' using batchid;
log(' HZ_CONTACT_PREFERENCES : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
execute immediate 'DELETE from HZ_STAGED_PARTY_SITES where PARTY_SITE_ID in
( select PARTY_SITE_ID FROM HZ_PARTY_SITES WHERE PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=:1 and status=''IDENTIFIED''))' using batchid;
log(' HZ_STAGED_PARTY_SITES : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
DELETE from HZ_PARTY_SITES where PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=batchid and status='IDENTIFIED');
log(' HZ_PARTY_SITES : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
execute immediate 'DELETE from HZ_CONTACT_PREFERENCES where CONTACT_LEVEL_TABLE_ID in
( select CONTACT_POINT_ID FROM HZ_CONTACT_POINTS WHERE OWNER_TABLE_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=:1 and status=''IDENTIFIED'')
and OWNER_TABLE_NAME=''HZ_PARTIES'') and CONTACT_LEVEL_TABLE=''HZ_CONTACT_POINTS''' using batchid;
log(' HZ_CONTACT_PREFERENCES : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
execute immediate 'DELETE from HZ_STAGED_CONTACT_POINTS where CONTACT_POINT_ID in
( select CONTACT_POINT_ID FROM HZ_CONTACT_POINTS WHERE OWNER_TABLE_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=:1 and status=''IDENTIFIED'')
and OWNER_TABLE_NAME=''HZ_PARTIES'')' using batchid;
log(' HZ_STAGED_CONTACT_POINTS : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
DELETE from HZ_CONTACT_POINTS where OWNER_TABLE_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=batchid and status='IDENTIFIED')
and OWNER_TABLE_NAME='HZ_PARTIES';
log(' HZ_CONTACT_POINTS : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
DELETE from HZ_PERSON_PROFILES where PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=batchid and status='IDENTIFIED');
log(' HZ_PERSON_PROFILES : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
DELETE from HZ_FINANCIAL_PROFILE where PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=batchid and status='IDENTIFIED');
log(' HZ_FINANCIAL_PROFILE : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
DELETE from HZ_REFERENCES where REFERENCED_PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=batchid and status='IDENTIFIED');
log(' HZ_REFERENCES : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
DELETE from HZ_CERTIFICATIONS where PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=batchid and status='IDENTIFIED');
log(' HZ_CERTIFICATIONS : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
DELETE from HZ_CREDIT_RATINGS where PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=batchid and status='IDENTIFIED');
log(' HZ_CREDIT_RATINGS : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
DELETE from HZ_SECURITY_ISSUED where PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=batchid and status='IDENTIFIED');
log(' HZ_SECURITY_ISSUED : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
DELETE from HZ_FINANCIAL_NUMBERS where FINANCIAL_REPORT_ID in
(select FINANCIAL_REPORT_ID FROM HZ_FINANCIAL_REPORTS WHERE PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=batchid and status='IDENTIFIED'));
log(' HZ_FINANCIAL_NUMBERS : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
DELETE from HZ_FINANCIAL_REPORTS where PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=batchid and status='IDENTIFIED');
log(' HZ_FINANCIAL_REPORTS : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
DELETE from HZ_ORGANIZATION_INDICATORS where PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=batchid and status='IDENTIFIED');
log(' HZ_FINANCIAL_REPORTS : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
DELETE from HZ_PERSON_INTEREST where PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=batchid and status='IDENTIFIED');
log(' HZ_FINANCIAL_REPORTS : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
DELETE from HZ_CITIZENSHIP where PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=batchid and status='IDENTIFIED');
log(' HZ_FINANCIAL_REPORTS : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
DELETE from HZ_WORK_CLASS where EMPLOYMENT_HISTORY_ID in
(select EMPLOYMENT_HISTORY_ID FROM HZ_EMPLOYMENT_HISTORY WHERE PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=batchid and status='IDENTIFIED'));
log(' HZ_WORK_CLASS : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
DELETE from HZ_EMPLOYMENT_HISTORY where PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=batchid and status='IDENTIFIED');
log(' HZ_EMPLOYMENT_HISTORY : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
DELETE from HZ_PERSON_LANGUAGE where PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=batchid and status='IDENTIFIED');
log(' HZ_PERSON_LANGUAGE : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
DELETE from HZ_EDUCATION where PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=batchid and status='IDENTIFIED');
log(' HZ_EDUCATION : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
DELETE from HZ_INDUSTRIAL_REFERENCE where PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=batchid and status='IDENTIFIED');
log(' HZ_INDUSTRIAL_REFERENCE : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
execute immediate 'DELETE from HZ_CODE_ASSIGNMENTS where OWNER_TABLE_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=:1 and status=''IDENTIFIED'')
and OWNER_TABLE_NAME=''HZ_PARTIES''' using batchid;
log(' HZ_CODE_ASSIGNMENTS : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
execute immediate 'DELETE from HZ_CONTACT_PREFERENCES where CONTACT_LEVEL_TABLE_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=:1 and status=''IDENTIFIED'')
and CONTACT_LEVEL_TABLE=''HZ_PARTIES''' using batchid;
log(' HZ_CONTACT_PREFERENCES : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
execute immediate 'DELETE from HZ_ORIG_SYS_REFERENCES where party_id in
(select candidate_party_id from hz_purge_candidates where batch_id=:1 and status=''IDENTIFIED'') ' using batchid;
log(' HZ_ORIG_SYS_REFERENCES : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
execute immediate 'DELETE from HZ_STAGED_PARTIES where PARTY_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=:1 and status=''IDENTIFIED'')' using batchid;
log(' HZ_STAGED_PARTIES : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
DELETE from AS_CHANGED_ACCOUNTS_ALL where CUSTOMER_ID in
(select candidate_party_id from hz_purge_candidates where batch_id=batchid and status='IDENTIFIED');
log(' AS_CHANGED_ACCOUNTS_ALL : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
delete from wsh_location_owners wlo
where wlo.owner_party_id in (select candidate_party_id
from hz_purge_candidates
where batch_id=batchid and status='IDENTIFIED')
and exists (
select 'x'
from wsh_location_owners wlo1
where wlo1.wsh_location_id = wlo.wsh_location_id and wlo1.owner_party_id = -1);
update wsh_location_owners wlo
set wlo.owner_party_id = -1
where wlo.owner_party_id in (select candidate_party_id
from hz_purge_candidates
where batch_id=batchid and status='IDENTIFIED'
and rownum = 1 )-- if more than one party has same location, only update one.
and not exists (
select 'x'
from wsh_location_owners wlo1
where wlo1.wsh_location_id = wlo.wsh_location_id and wlo1.owner_party_id = -1);
delete from wsh_location_owners wlo
where wlo.owner_party_id in (select candidate_party_id
from hz_purge_candidates
where batch_id=batchid and status='IDENTIFIED')
and wlo.owner_party_id <> -1;
Delete from zx_party_tax_profile PTP
where ptp.party_type_code = 'THIRD_PARTY'
and ptp.party_id in (select candidate_party_id
from hz_purge_candidates
where batch_id=batchid and status='IDENTIFIED')
and not exists (Select 'x'
from zx_registrations reg
where ptp.party_tax_profile_id = reg.party_tax_profile_id)
and not exists (Select 'x'
from zx_exemptions ex
where ptp.party_tax_profile_id = ex.party_tax_profile_id)
and not exists (Select 'x'
from ZX_REPORT_CODES_ASSOC assoc
where assoc.entity_code = 'ZX_PARTY_TAX_PROFILE'
and assoc.ENTITY_ID = ptp.party_tax_profile_id)
and not exists (Select 'x'
from hz_code_assignments HCA
where HCA.OWNER_TABLE_NAME = 'ZX_PARTY_TAX_PROFILE'
AND HCA.OWNER_TABLE_ID = PTP.PARTY_TAX_PROFILE_ID);
DELETE from HZ_PARTIES where party_id in
(select candidate_party_id from hz_purge_candidates where batch_id=batchid and status='IDENTIFIED');
log(' HZ_PARTIES : Deleted '||SQL%ROWCOUNT||' rows',conc_prg);
execute immediate 'update hz_relationships set party_id=null where party_id in
(select pur_cand.candidate_party_id from hz_purge_candidates pur_cand, hz_parties parties where pur_cand.batch_id=:1 and
pur_cand.candidate_party_id = parties.party_id and parties.party_type=''PARTY_RELATIONSHIP'' )' using batchid;
delete from hz_parties where party_id in (select party_id from hz_relationships
where (subject_id in (select candidate_party_id
from hz_purge_candidates
where batch_id=batchid and status='IDENTIFIED')
or object_id in (select candidate_party_id
from hz_purge_candidates
where batch_id=batchid and status='IDENTIFIED')))
and status = 'M';
delete from hz_relationships where (subject_id in (select candidate_party_id
from hz_purge_candidates
where batch_id=batchid and status='IDENTIFIED')
or object_id in (select candidate_party_id
from hz_purge_candidates
where batch_id=batchid and status='IDENTIFIED'))
and status = 'M';
update hz_purge_candidates set status='PURGED' where batch_id=batchid and status='IDENTIFIED';
update hz_purge_candidates set status='PURGED' where candidate_party_id in (
select candidate_party_id from hz_purge_candidates where batch_id=batchid and status='PURGED')
and batch_id<>batchid;
/* update the status of purged parties in table 'HZ_PURGE_BATCHES to 'PURGE_COMPLETED' */
update hz_purge_batches set status='PURGE_COMPLETE',purge_date=sysdate where batch_id=batchid;
update hz_purge_batches set status='PURGE_ERROR' where batch_id=batchid;
update hz_purge_batches set status='PURGE_ERROR' where batch_id=batchid;
update hz_purge_batches set status='PURGE_ERROR' where batch_id=batchid;
insertrows number;
select count(*) from hz_purge_candidates where candidate_party_id=p_id and status<>'PURGED';
insert into hz_purge_candidates(BATCH_ID,CANDIDATE_PARTY_ID,PARTY_NAME,PARTY_NUMBER,ADDRESSES,PHONE_NUMBERS,COUNTRY,STATUS,CREATION_DATE,
LAST_UPDATE_LOGIN,LAST_UPDATE_DATE,LAST_UPDATED_BY,CREATED_BY)
select to_number('-1'), a.party_id, substr(a.party_name,1,250), a.party_number,
a.address1||','||a.city||','||a.state||','||a.country||' '||a.postal_code,
cp.PHONE_AREA_CODE||'-'||cp.PHONE_COUNTRY_CODE||'-'||cp.PHONE_NUMBER, a.country, 'IDENTIFIED',
sysdate, fnd_global.login_id, sysdate, fnd_global.user_id, fnd_global.user_id
from hz_parties a , hz_contact_points cp where a.party_id = p_party_id and
cp.owner_table_id(+)=a.party_id and cp.contact_point_type(+)='PHONE' and cp.primary_flag(+)='Y' and
cp.owner_table_name(+)='HZ_PARTIES';
DELETE from HZ_ORGANIZATION_PROFILES where PARTY_ID = p_party_id;
execute immediate 'DELETE from HZ_CONTACT_PREFERENCES where CONTACT_LEVEL_TABLE_ID in
( select CONTACT_POINT_ID FROM HZ_CONTACT_POINTS WHERE OWNER_TABLE_ID in
(SELECT PARTY_SITE_ID FROM HZ_PARTY_SITES WHERE PARTY_ID = :1)and OWNER_TABLE_NAME=''HZ_PARTY_SITES'')
and CONTACT_LEVEL_TABLE=''HZ_CONTACT_POINTS''' using p_party_id;
execute immediate 'DELETE from HZ_STAGED_CONTACT_POINTS where CONTACT_POINT_ID in
( select CONTACT_POINT_ID FROM HZ_CONTACT_POINTS WHERE OWNER_TABLE_ID in
(SELECT PARTY_SITE_ID FROM HZ_PARTY_SITES WHERE PARTY_ID = :1) and OWNER_TABLE_NAME=''HZ_PARTY_SITES'')' using p_party_id;
DELETE from HZ_CONTACT_POINTS where OWNER_TABLE_ID in
( select PARTY_SITE_ID FROM HZ_PARTY_SITES WHERE PARTY_ID = p_party_id) and OWNER_TABLE_NAME='HZ_PARTY_SITES';
DELETE from HZ_ORG_CONTACT_ROLES where ORG_CONTACT_ID in
( select ORG_CONTACT_ID FROM HZ_ORG_CONTACTS WHERE PARTY_SITE_ID in (
SELECT PARTY_SITE_ID FROM HZ_PARTY_SITES WHERE PARTY_ID = p_party_id));
execute immediate 'DELETE from HZ_STAGED_CONTACTS where ORG_CONTACT_ID in
( select ORG_CONTACT_ID FROM HZ_ORG_CONTACTS WHERE PARTY_SITE_ID in
(SELECT PARTY_SITE_ID FROM HZ_PARTY_SITES WHERE PARTY_ID = :1))' using p_party_id;
DELETE from HZ_ORG_CONTACTS where PARTY_SITE_ID in
( select PARTY_SITE_ID FROM HZ_PARTY_SITES WHERE PARTY_ID = p_party_id);
DELETE from HZ_PARTY_SITE_USES where PARTY_SITE_ID in
( select PARTY_SITE_ID FROM HZ_PARTY_SITES WHERE PARTY_ID = p_party_id);
execute immediate 'DELETE from HZ_CODE_ASSIGNMENTS where OWNER_TABLE_ID in
( select PARTY_SITE_ID FROM HZ_PARTY_SITES WHERE PARTY_ID = :1) and OWNER_TABLE_NAME=''HZ_PARTY_SITES''' using p_party_id;
execute immediate 'DELETE from HZ_CONTACT_PREFERENCES where CONTACT_LEVEL_TABLE_ID in
( select PARTY_SITE_ID FROM HZ_PARTY_SITES WHERE PARTY_ID = :1) and CONTACT_LEVEL_TABLE=''HZ_PARTY_SITES''' using p_party_id;
execute immediate 'DELETE from HZ_STAGED_PARTY_SITES where PARTY_SITE_ID in
( select PARTY_SITE_ID FROM HZ_PARTY_SITES WHERE PARTY_ID = :1)' using p_party_id;
DELETE from HZ_PARTY_SITES where PARTY_ID = p_party_id;
execute immediate 'DELETE from HZ_CONTACT_PREFERENCES where CONTACT_LEVEL_TABLE_ID in
( select CONTACT_POINT_ID FROM HZ_CONTACT_POINTS WHERE OWNER_TABLE_ID = :1 and OWNER_TABLE_NAME=''HZ_PARTIES'')
and CONTACT_LEVEL_TABLE=''HZ_CONTACT_POINTS''' using p_party_id;
execute immediate 'DELETE from HZ_STAGED_CONTACT_POINTS where CONTACT_POINT_ID in
( select CONTACT_POINT_ID FROM HZ_CONTACT_POINTS WHERE OWNER_TABLE_ID = :1 and OWNER_TABLE_NAME=''HZ_PARTIES'')' using p_party_id;
DELETE from HZ_CONTACT_POINTS where OWNER_TABLE_ID = p_party_id and OWNER_TABLE_NAME='HZ_PARTIES';
DELETE from HZ_PERSON_PROFILES where PARTY_ID = p_party_id;
DELETE from HZ_FINANCIAL_PROFILE where PARTY_ID = p_party_id;
DELETE from HZ_REFERENCES where REFERENCED_PARTY_ID = p_party_id;
DELETE from HZ_CERTIFICATIONS where PARTY_ID = p_party_id;
DELETE from HZ_CREDIT_RATINGS where PARTY_ID = p_party_id;
DELETE from HZ_SECURITY_ISSUED where PARTY_ID = p_party_id;
DELETE from HZ_FINANCIAL_NUMBERS where FINANCIAL_REPORT_ID in
( select FINANCIAL_REPORT_ID FROM HZ_FINANCIAL_REPORTS WHERE PARTY_ID = p_party_id);
DELETE from HZ_FINANCIAL_REPORTS where PARTY_ID = p_party_id;
DELETE from HZ_ORGANIZATION_INDICATORS where PARTY_ID = p_party_id;
DELETE from HZ_PERSON_INTEREST where PARTY_ID = p_party_id;
DELETE from HZ_CITIZENSHIP where PARTY_ID = p_party_id;
DELETE from HZ_WORK_CLASS where EMPLOYMENT_HISTORY_ID in
(select EMPLOYMENT_HISTORY_ID FROM HZ_EMPLOYMENT_HISTORY WHERE PARTY_ID = p_party_id);
DELETE from HZ_EMPLOYMENT_HISTORY where PARTY_ID = p_party_id;
DELETE from HZ_PERSON_LANGUAGE where PARTY_ID = p_party_id;
DELETE from HZ_EDUCATION where PARTY_ID = p_party_id;
DELETE from HZ_INDUSTRIAL_REFERENCE where PARTY_ID = p_party_id;
execute immediate 'DELETE from HZ_CODE_ASSIGNMENTS where OWNER_TABLE_ID = :1 and OWNER_TABLE_NAME=''HZ_PARTIES''' using p_party_id;
execute immediate 'DELETE from HZ_CONTACT_PREFERENCES where CONTACT_LEVEL_TABLE_ID = :1 and CONTACT_LEVEL_TABLE=''HZ_PARTIES''' using p_party_id;
execute immediate 'DELETE from HZ_ORIG_SYS_REFERENCES where party_id = :1' using p_party_id;
execute immediate 'DELETE from HZ_STAGED_PARTIES where PARTY_ID = :1' using p_party_id;
DELETE from AS_CHANGED_ACCOUNTS_ALL where CUSTOMER_ID = p_party_id;
delete from wsh_location_owners wlo
where wlo.owner_party_id = p_party_id
and exists (
select 'x'
from wsh_location_owners wlo1
where wlo1.wsh_location_id = wlo.wsh_location_id and wlo1.owner_party_id = -1);
update wsh_location_owners wlo
set wlo.owner_party_id = -1
where wlo.owner_party_id = p_party_id
and not exists (
select 'x'
from wsh_location_owners wlo1
where wlo1.wsh_location_id = wlo.wsh_location_id and wlo1.owner_party_id = -1);
Delete from zx_party_tax_profile PTP
where ptp.party_type_code = 'THIRD_PARTY'
and ptp.party_id = p_party_id
and not exists (Select 'x'
from zx_registrations reg
where ptp.party_tax_profile_id = reg.party_tax_profile_id)
and not exists (Select 'x'
from zx_exemptions ex
where ptp.party_tax_profile_id = ex.party_tax_profile_id)
and not exists (Select 'x'
from ZX_REPORT_CODES_ASSOC assoc
where assoc.entity_code = 'ZX_PARTY_TAX_PROFILE'
and assoc.ENTITY_ID = ptp.party_tax_profile_id)
and not exists (Select 'x'
from hz_code_assignments HCA
where HCA.OWNER_TABLE_NAME = 'ZX_PARTY_TAX_PROFILE'
AND HCA.OWNER_TABLE_ID = PTP.PARTY_TAX_PROFILE_ID);
DELETE from HZ_PARTIES where party_id = p_party_id;
execute immediate 'update hz_relationships set party_id=null where party_id=:1 and party_id in
(select party_id from hz_parties where party_type = ''PARTY_RELATIONSHIP'')' using p_party_id;
delete from hz_parties where party_id in (select party_id from hz_relationships
where (subject_id = p_party_id or object_id = p_party_id))
and status = 'M';
delete from hz_relationships where (subject_id = p_party_id or object_id = p_party_id) and status = 'M';
/* update status to 'PURGED' in hz_purge_candidates for the purged parties */
update hz_purge_candidates set status='PURGED' where candidate_party_id=p_party_id;
select count(*) from hz_application_trans_gt where app_id=appid;
insert into hz_application_trans_gt(app_id) values(appid);
insert into hz_purge_gt(party_id) values(single_party);
SELECT DATA_TYPE FROM sys.all_tab_columns
WHERE table_name = p_table
AND COLUMN_NAME = p_column
AND owner = schema1;
select entity_name, fk_column_name, merge_dict_id, dict_application_id
from hz_merge_dictionary
where fk_data_type is null;
update hz_merge_dictionary
set fk_data_type = l_data_type
where merge_dict_id = l_merge_dict_id;
Select application_short_name from fnd_application where application_id=app_id;
select min(column_position) from dba_ind_columns where table_name = ent_name
and column_name = ent_col_name
and index_owner = schema1 and table_owner = schema1;
select index_name, column_position from dba_ind_columns
where table_name = ent_name and column_name = colmn_name
and index_owner = schema1 and table_owner = schema1;
select column_name from dba_ind_columns where table_name = ent_name
and index_name = ind_name
and column_position
select 'Y' from dual where
(ent_name,colmn_name)
in (('AS_ACCESSES_ALL', 'CUSTOMER_ID'),('AS_ACCESSES_ALL', 'ADDRESS_ID'),('AS_ACCESSES_ALL', 'PARTNER_CUSTOMER_ID'),
('AS_ACCESSES_ALL', 'PARTNER_CONT_PARTY_ID'),('AS_ACCESSES_ALL', 'PARTNER_ADDRESS_ID'),('ASG_PARTY_ACC_V', 'PARTY_ID'),
('OKE_K_FUNDING_SOURCES_PM_HV', 'K_PARTY_ID'),('IGW_PROP_PERSONS_TCA_V', 'PERSON_PARTY_ID'),
('MIS_HZ_MERGE_VETO_PARTIES', 'PARTY_ID'),('MIS_HZ_MERGE_VETO_PARTY_SITES', 'PARTY_SITE_ID'),('JTF_PERZ_QUERY_PARAM','PARAMETER_VALUE'));
select instr(join_clause,col_name) from dual;
PROCEDURE delete_template
(e1 VARCHAR2, fk1 VARCHAR2,pk1 VARCHAR2,j1 VARCHAR2, pe1 VARCHAR2, fk_data_typ1 VARCHAR2,
first VARCHAR2, concat_string OUT NOCOPY VARCHAR2, cnt NUMBER) IS
e2 varchar2(50);
select decode(entity_name,'HZ_PARTY_RELATIONSHIPS','HZ_RELATIONSHIPS',entity_name) entity_name, fk_column_name,
decode(entity_name,'HZ_PARTY_RELATIONSHIPS','RELATIONSHIP_ID',pk_column_name) pk_column_name,
decode(entity_name,'HZ_PARTY_RELATIONSHIPS', join_clause || ' AND subject_table_name = ''HZ_PARTIES'' AND object_table_name = ''HZ_PARTIES''
AND directional_flag = ''F''', join_clause) join_clause, parent_entity_name,fk_data_type
from hz_merge_dictionary where entity_name = parent;
select decode(entity_name,'HZ_PARTY_RELATIONSHIPS','HZ_RELATIONSHIPS',entity_name) entity_name, fk_column_name,
decode(entity_name,'HZ_PARTY_RELATIONSHIPS','RELATIONSHIP_ID',pk_column_name) pk_column_name,
decode(entity_name,'HZ_PARTY_RELATIONSHIPS', join_clause || ' AND subject_table_name = ''HZ_PARTIES'' AND object_table_name = ''HZ_PARTIES''
AND directional_flag = ''F''', join_clause) join_clause,
parent_entity_name,fk_data_type
from hz_merge_dictionary where entity_name = parent2;
select decode(instr(j1,'group'),0,j1,substr(j1,1,instr(j1,'group')-1)) into p3 from dual;
l_sql := 'delete from hz_purge_gt temp where ';
p1:= ' exists (select ''Y'' from '||e1;
l_sql := 'delete from hz_purge_gt temp where 1<>1 ';
p1:= ' or exists (select ''Y'' from '||e1;
l_sql := 'delete from hz_purge_gt temp where ';
p1:= partyid||' in (select /*+ parallel(xx)*/ xx.'||fk1||' from '||e1;
--select decode(instr(j2,'group'),0,' and '||j2,' and '||substr(j1,1,instr(j1,'group')-1)) into p3 from dual;
select decode(instr(j2,'group'),0,j2,substr(j1,1,instr(j1,'group')-1)) into p3 from dual;
l_sql := 'delete from hz_purge_gt temp where ';
p1:= ' exists (select ''Y'' from '||e2;
p1:= ' or exists (select ''Y'' from '||e2;
l_sql := 'delete from hz_purge_gt temp where 1<>1 ';
p1:= ' or exists (select ''Y'' from '||e2;
l_sql := 'delete from hz_purge_gt temp where ';
p1:= partyid||' in (select /*+ parallel (xx)*/ xx.'||fk2||' from '||e2;
p1:= ' or '||partyid||' in (select /*+ parallel (xx)*/ xx.'||fk2||' from '||e2;
--select decode(instr(j1,'group'),0,' and '||j1,' and '||substr(j1,1,instr(j1,'group')-1)) into p7 from dual;
select decode(instr(j1,'group'),0,j1,substr(j1,1,instr(j1,'group')-1)) into p7 from dual;
p5:= ' in (select /*+ parallel(yy)*/ yy.'||fk1||' from '||e1;
p5 := '(select ''Y'' from '||e1;
select decode(instr(j3,'group'),0,j3,substr(j3,1,instr(j3,'group')-1)) into p3 from dual;
l_sql := 'delete from hz_purge_gt temp where ';
p1:= ' exists (select ''Y'' from '||e3;
p1:= ' or exists (select ''Y'' from '||e3;
l_sql := 'delete from hz_purge_gt temp where 1<>1 ';
p1:= ' or exists (select ''Y'' from '||e3;
l_sql := 'delete from hz_purge_gt temp where ';
p1:= partyid||' in (select /*+ parallel(xx)*/ ''Y'' from '||e3;
p1:= ' or '||partyid||' in (select /*+ parallel(xx)*/ ''Y'' from '||e3;
--select decode(instr(j2,'group'),0,' and '||j2,' and '||substr(j2,1,instr(j2,'group')-1)) into p7 from dual;
select decode(instr(j2,'group'),0,j2,substr(j2,1,instr(j2,'group')-1)) into p7 from dual;
p5:= ' in (select /*+ parallel(yy)*/ yy.'||fk2||' from '||e2;
p5:= ' (select ''Y'' from '||e2;
select decode(instr(j1,'group'),0,j1,substr(j1,1,instr(j1,'group')-1)) into p11 from dual;
p9:= ' in (select /*+ parallel(zz)*/ yy.'||pk2||' from '||e1;
p9:= ' (select ''Y'' from '||e1;