To be honest im not a technical person below is the full sql is there away to rewrite the script and replace dq_pattern?
SELECT ( select name
from hr_all_organization_units
where organization_id = hcasa.ORG_ID ) ou,
to_number (hca.ACCOUNT_NUMBER) account_number,
to_number (hp.PARTY_NUMBER) party_number,
to_number (hps.PARTY_SITE_NUMBER) party_site_number,
hp.PARTY_NAME,
hp.tax_reference,
hp.jgzz_fiscal_code,
hl.ADDRESS1,
hl.ADDRESS2,
hl.ADDRESS3,
hl.ADDRESS4,
hl.POSTAL_CODE,
dq_pattern(hl.POSTAL_CODE) current_postal_code_pattern,
'ddddd' valid_postal_code_patterns,
hl.CITY,
hl.PROVINCE,
hl.COUNTY,
hl.COUNTRY,
hl.STATE,
hcasa.creation_date site_creation_date,
( select user_name
from fnd_user
where user_id = hcasa.created_by ) site_created_by,
hcasa.last_update_date site_last_update_date,
( select user_name
from fnd_user
where user_id = hcasa.last_updated_by ) site_last_updated_by
FROM hz_parties hp,
hz_cust_accounts hca,
hz_cust_acct_sites_all hcasa,
hz_party_sites hps,
hz_locations hl
WHERE hp.PARTY_TYPE = 'ORGANIZATION'
AND hp.PARTY_ID = hca.PARTY_ID
AND hca.CUST_ACCOUNT_ID = hcasa.CUST_ACCOUNT_ID
AND NOT ((hp.status = 'I') and (hca.status = 'I'))
AND hcasa.PARTY_SITE_ID = hps.PARTY_SITE_ID
AND hps.LOCATION_ID = hl.LOCATION_ID
AND hca.customer_type = 'R'
AND hp.status = 'A'
AND hca.status = 'A'
AND hps.status = 'A'
AND hcasa.status = 'A'
and dq_pattern(hl.POSTAL_CODE) not in ('ddddd')
and hl.country in ('HR','FR','FI','DE','IT','TR','UA','PK','BA','DZ','EE','EG','JO','LK','MA','MC','ME','MN','GR','NP')
and hca.account_number not in ('6540888','1374335','57358','58915','3140874','3370379','1374370','57439')
union
SELECT ( select name
from hr_all_organization_units
where organization_id = hcasa.ORG_ID ) ou,
to_number (hca.ACCOUNT_NUMBER) account_number,
to_number (hp.PARTY_NUMBER) party_number,
to_number (hps.PARTY_SITE_NUMBER) party_site_number,
hp.PARTY_NAME,
hp.tax_reference,
hp.jgzz_fiscal_code,
hl.ADDRESS1,
hl.ADDRESS2,
hl.ADDRESS3,
hl.ADDRESS4,
hl.POSTAL_CODE,
dq_pattern(hl.POSTAL_CODE) current_postal_code_pattern,
'ud_duu, udd_duu, uud_duu, uudd_duu, udu_duu, uudu_duu' valid_postal_code_patterns,
hl.CITY,
hl.PROVINCE,
hl.COUNTY,
hl.COUNTRY,
hl.STATE,
hcasa.creation_date site_creation_date,
( select user_name
from fnd_user
where user_id = hcasa.created_by ) site_created_by,
hcasa.last_update_date site_last_update_date,
( select user_name
from fnd_user
where user_id = hcasa.last_updated_by ) site_last_updated_by
FROM hz_parties hp,
hz_cust_accounts hca,
hz_cust_acct_sites_all hcasa,
hz_party_sites hps,
hz_locations hl
WHERE hp.PARTY_TYPE = 'ORGANIZATION'
AND hp.PARTY_ID = hca.PARTY_ID
AND hca.CUST_ACCOUNT_ID = hcasa.CUST_ACCOUNT_ID
AND NOT ((hp.status = 'I') and (hca.status = 'I'))
AND hcasa.PARTY_SITE_ID = hps.PARTY_SITE_ID
AND hps.LOCATION_ID = hl.LOCATION_ID
AND hca.customer_type = 'R'
AND hp.status = 'A'
AND hca.status = 'A'
AND hps.status = 'A'
AND hcasa.status = 'A'
and dq_pattern(hl.POSTAL_CODE) not in ('ud_duu','udd_duu','uud_duu','uudd_duu','udu_duu','uudu_duu')
and hl.country = 'GB'
and hps.PARTY_SITE_NUMBER not in ('59040365')
and hca.account_number not in ('6540888','1374335','57358','58915','3140874','3370379','1374370','57439')
union
SELECT ( select name
from hr_all_organization_units
where organization_id = hcasa.ORG_ID ) ou,
to_number (hca.ACCOUNT_NUMBER) account_number,
to_number (hp.PARTY_NUMBER) party_number,
to_number (hps.PARTY_SITE_NUMBER) party_site_number,
hp.PARTY_NAME,
hp.tax_reference,
hp.jgzz_fiscal_code,
hl.ADDRESS1,
hl.ADDRESS2,
hl.ADDRESS3,
hl.ADDRESS4,
hl.POSTAL_CODE,
dq_pattern(hl.POSTAL_CODE) current_postal_code_pattern,
'dddd' valid_postal_code_patterns,
hl.CITY,
hl.PROVINCE,
hl.COUNTY,
hl.COUNTRY,
hl.STATE,
hcasa.creation_date site_creation_date,
( select user_name
from fnd_user
where user_id = hcasa.created_by ) site_created_by,
hcasa.last_update_date site_last_update_date,
( select user_name
from fnd_user
where user_id = hcasa.last_updated_by ) site_last_updated_by
FROM hz_parties hp,
hz_cust_accounts hca,
hz_cust_acct_sites_all hcasa,
hz_party_sites hps,
hz_locations hl
WHERE hp.PARTY_TYPE = 'ORGANIZATION'
AND hp.PARTY_ID = hca.PARTY_ID
AND hca.CUST_ACCOUNT_ID = hcasa.CUST_ACCOUNT_ID
AND NOT ((hp.status = 'I') and (hca.status = 'I'))
AND hcasa.PARTY_SITE_ID = hps.PARTY_SITE_ID
AND hps.LOCATION_ID = hl.LOCATION_ID
AND hca.customer_type = 'R'
AND hp.status = 'A'
AND hca.status = 'A'
AND hps.status = 'A'
AND hcasa.status = 'A'
and dq_pattern(hl.POSTAL_CODE) not in ('dddd')
and hl.country in ('AM','AT','DK','HU','ZA','CH','BE','BD','BG','CY','GE','GW','LU','MK')
and hca.account_number not in ('6540888','1374335','57358','58915','3140874','3370379','1374370','57439')
union
SELECT ( select name
from hr_all_organization_units
where organization_id = hcasa.ORG_ID ) ou,
to_number (hca.ACCOUNT_NUMBER) account_number,
to_number (hp.PARTY_NUMBER) party_number,
to_number (hps.PARTY_SITE_NUMBER) party_site_number,
hp.PARTY_NAME,
hp.tax_reference,
hp.jgzz_fiscal_code,
hl.ADDRESS1,
hl.ADDRESS2,
hl.ADDRESS3,
hl.ADDRESS4,
hl.POSTAL_CODE,
dq_pattern(hl.POSTAL_CODE) current_postal_code_pattern,
'ddd_dd' valid_postal_code_patterns,
hl.CITY,
hl.PROVINCE,
hl.COUNTY,
hl.COUNTRY,
hl.STATE,
hcasa.creation_date site_creation_date,
( select user_name
from fnd_user
where user_id = hcasa.created_by ) site_created_by,
hcasa.last_update_date site_last_update_date,
( select user_name
from fnd_user
where user_id = hcasa.last_updated_by ) site_last_updated_by
FROM hz_parties hp,
hz_cust_accounts hca,
hz_cust_acct_sites_all hcasa,
hz_party_sites hps,
hz_locations hl
WHERE hp.PARTY_TYPE = 'ORGANIZATION'
AND hp.PARTY_ID = hca.PARTY_ID
AND hca.CUST_ACCOUNT_ID = hcasa.CUST_ACCOUNT_ID
AND NOT ((hp.status = 'I') and (hca.status = 'I'))
AND hcasa.PARTY_SITE_ID = hps.PARTY_SITE_ID
AND hps.LOCATION_ID = hl.LOCATION_ID
AND hca.customer_type = 'R'
AND hp.status = 'A'
AND hca.status = 'A'
AND hps.status = 'A'
AND hcasa.status = 'A'
and dq_pattern(hl.POSTAL_CODE) not in ('ddd_dd')
and hl.country in ('CZ','SL','SE')
and hca.account_number not in ('6540888','1374335','57358','58915','3140874','3370379','1374370','57439')
union
SELECT ( select name
from hr_all_organization_units
where organization_id = hcasa.ORG_ID ) ou,
to_number (hca.ACCOUNT_NUMBER) account_number,
to_number (hp.PARTY_NUMBER) party_number,
to_number (hps.PARTY_SITE_NUMBER) party_site_number,
hp.PARTY_NAME,
hp.tax_reference,
hp.jgzz_fiscal_code,
hl.ADDRESS1,
hl.ADDRESS2,
hl.ADDRESS3,
hl.ADDRESS4,
hl.POSTAL_CODE,
dq_pattern(hl.POSTAL_CODE) current_postal_code_pattern,
'dddddd' valid_postal_code_patterns,
hl.CITY,
hl.PROVINCE,
hl.COUNTY,
hl.COUNTRY,
hl.STATE,
hcasa.creation_date site_creation_date,
( select user_name
from fnd_user
where user_id = hcasa.created_by ) site_created_by,
hcasa.last_update_date site_last_update_date,
( select user_name
from fnd_user
where user_id = hcasa.last_updated_by ) site_last_updated_by
FROM hz_parties hp,
hz_cust_accounts hca,
hz_cust_acct_sites_all hcasa,
hz_party_sites hps,
hz_locations hl
WHERE hp.PARTY_TYPE = 'ORGANIZATION'
AND hp.PARTY_ID = hca.PARTY_ID
AND hca.CUST_ACCOUNT_ID = hcasa.CUST_ACCOUNT_ID
AND NOT ((hp.status = 'I') and (hca.status = 'I'))
AND hcasa.PARTY_SITE_ID = hps.PARTY_SITE_ID
AND hps.LOCATION_ID = hl.LOCATION_ID
AND hca.customer_type = 'R'
AND hp.status = 'A'
AND hca.status = 'A'
AND hps.status = 'A'
AND hcasa.status = 'A'
and dq_pattern(hl.POSTAL_CODE) not in ('dddddd')
and hl.country in ('IN','RU','BY','KG','KZ')
and hca.account_number not in ('6540888','1374335','57358','58915','3140874','3370379','1374370','57439')
union
SELECT ( select name
from hr_all_organization_units
where organization_id = hcasa.ORG_ID ) ou,
to_number (hca.ACCOUNT_NUMBER) account_number,
to_number (hp.PARTY_NUMBER) party_number,
to_number (hps.PARTY_SITE_NUMBER) party_site_number,
hp.PARTY_NAME,
hp.tax_reference,
hp.jgzz_fiscal_code,
hl.ADDRESS1,
hl.ADDRESS2,
hl.ADDRESS3,
hl.ADDRESS4,
hl.POSTAL_CODE,
dq_pattern(hl.POSTAL_CODE) current_postal_code_pattern,
'dddd_uu' valid_postal_code_patterns,
hl.CITY,
hl.PROVINCE,
hl.COUNTY,
hl.COUNTRY,
hl.STATE,
hcasa.creation_date site_creation_date,
( select user_name
from fnd_user
where user_id = hcasa.created_by ) site_created_by,
hcasa.last_update_date site_last_update_date,
( select user_name
from fnd_user
where user_id = hcasa.last_updated_by ) site_last_updated_by
FROM hz_parties hp,
hz_cust_accounts hca,
hz_cust_acct_sites_all hcasa,
hz_party_sites hps,
hz_locations hl
WHERE hp.PARTY_TYPE = 'ORGANIZATION'
AND hp.PARTY_ID = hca.PARTY_ID
AND hca.CUST_ACCOUNT_ID = hcasa.CUST_ACCOUNT_ID
AND NOT ((hp.status = 'I') and (hca.status = 'I'))
AND hcasa.PARTY_SITE_ID = hps.PARTY_SITE_ID
AND hps.LOCATION_ID = hl.LOCATION_ID
AND hca.customer_type = 'R'
AND hp.status = 'A'
AND hca.status = 'A'
AND hps.status = 'A'
AND hcasa.status = 'A'
and dq_pattern(hl.POSTAL_CODE) not in ('dddd_uu')
and hl.country = 'NL'
union
SELECT ( select name
from hr_all_organization_units
where organization_id = hcasa.ORG_ID ) ou,
to_number (hca.ACCOUNT_NUMBER) account_number,
to_number (hp.PARTY_NUMBER) party_number,
to_number (hps.PARTY_SITE_NUMBER) party_site_number,
hp.PARTY_NAME,
hp.tax_reference,
hp.jgzz_fiscal_code,
hl.ADDRESS1,
hl.ADDRESS2,
hl.ADDRESS3,
hl.ADDRESS4,
hl.POSTAL_CODE,
dq_pattern(hl.POSTAL_CODE) current_postal_code_pattern,
'dd-ddd' valid_postal_code_patterns,
hl.CITY,
hl.PROVINCE,
hl.COUNTY,
hl.COUNTRY,
hl.STATE,
hcasa.creation_date site_creation_date,
( select user_name
from fnd_user
where user_id = hcasa.created_by ) site_created_by,
hcasa.last_update_date site_last_update_date,
( select user_name
from fnd_user
where user_id = hcasa.last_updated_by ) site_last_updated_by
FROM hz_parties hp,
hz_cust_accounts hca,
hz_cust_acct_sites_all hcasa,
hz_party_sites hps,
hz_locations hl
WHERE hp.PARTY_TYPE = 'ORGANIZATION'
AND hp.PARTY_ID = hca.PARTY_ID
AND hca.CUST_ACCOUNT_ID = hcasa.CUST_ACCOUNT_ID
AND NOT ((hp.status = 'I') and (hca.status = 'I'))
AND hcasa.PARTY_SITE_ID = hps.PARTY_SITE_ID
AND hps.LOCATION_ID = hl.LOCATION_ID
AND hca.customer_type = 'R'
AND hp.status = 'A'
AND hca.status = 'A'
AND hps.status = 'A'
AND hcasa.status = 'A'
and dq_pattern(hl.POSTAL_CODE) not in ('dd-ddd')
and hl.country = 'PL'
and hca.account_number not in ('6540888','1374335','57358','58915','3140874','3370379','1374370','57439')
union
SELECT ( select name
from hr_all_organization_units
where organization_id = hcasa.ORG_ID ) ou,
to_number (hca.ACCOUNT_NUMBER) account_number,
to_number (hp.PARTY_NUMBER) party_number,
to_number (hps.PARTY_SITE_NUMBER) party_site_number,
hp.PARTY_NAME,
hp.tax_reference,
hp.jgzz_fiscal_code,
hl.ADDRESS1,
hl.ADDRESS2,
hl.ADDRESS3,
hl.ADDRESS4,
hl.POSTAL_CODE,
dq_pattern(hl.POSTAL_CODE) current_postal_code_pattern,
'ddddddd,ddddd' valid_postal_code_patterns,
hl.CITY,
hl.PROVINCE,
hl.COUNTY,
hl.COUNTRY,
hl.STATE,
hcasa.creation_date site_creation_date,
( select user_name
from fnd_user
where user_id = hcasa.created_by ) site_created_by,
hcasa.last_update_date site_last_update_date,
( select user_name
from fnd_user
where user_id = hcasa.last_updated_by ) site_last_updated_by
FROM hz_parties hp,
hz_cust_accounts hca,
hz_cust_acct_sites_all hcasa,
hz_party_sites hps,
hz_locations hl
WHERE hp.PARTY_TYPE = 'ORGANIZATION'
AND hp.PARTY_ID = hca.PARTY_ID
AND hca.CUST_ACCOUNT_ID = hcasa.CUST_ACCOUNT_ID
AND NOT ((hp.status = 'I') and (hca.status = 'I'))
AND hcasa.PARTY_SITE_ID = hps.PARTY_SITE_ID
AND hps.LOCATION_ID = hl.LOCATION_ID
AND hca.customer_type = 'R'
AND hp.status = 'A'
AND hca.status = 'A'
AND hps.status = 'A'
AND hcasa.status = 'A'
and dq_pattern(hl.POSTAL_CODE) not in ('ddddddd','ddddd')
and hl.country in ('IL')
and hca.account_number not in ('6540888','1374335','57358','58915','3140874','3370379','1374370','57439')
union
SELECT ( select name
from hr_all_organization_units
where organization_id = hcasa.ORG_ID ) ou,
to_number (hca.ACCOUNT_NUMBER) account_number,
to_number (hp.PARTY_NUMBER) party_number,
to_number (hps.PARTY_SITE_NUMBER) party_site_number,
hp.PARTY_NAME,
hp.tax_reference,
hp.jgzz_fiscal_code,
hl.ADDRESS1,
hl.ADDRESS2,
hl.ADDRESS3,
hl.ADDRESS4,
hl.POSTAL_CODE,
dq_pattern(hl.POSTAL_CODE) current_postal_code_pattern,
'uu-dddd' valid_postal_code_patterns,
hl.CITY,
hl.PROVINCE,
hl.COUNTY,
hl.COUNTRY,
hl.STATE,
hcasa.creation_date site_creation_date,
( select user_name
from fnd_user
where user_id = hcasa.created_by ) site_created_by,
hcasa.last_update_date site_last_update_date,
( select user_name
from fnd_user
where user_id = hcasa.last_updated_by ) site_last_updated_by
FROM hz_parties hp,
hz_cust_accounts hca,
hz_cust_acct_sites_all hcasa,
hz_party_sites hps,
hz_locations hl
WHERE hp.PARTY_TYPE = 'ORGANIZATION'
AND hp.PARTY_ID = hca.PARTY_ID
AND hca.CUST_ACCOUNT_ID = hcasa.CUST_ACCOUNT_ID
AND NOT ((hp.status = 'I') and (hca.status = 'I'))
AND hcasa.PARTY_SITE_ID = hps.PARTY_SITE_ID
AND hps.LOCATION_ID = hl.LOCATION_ID
AND hca.customer_type = 'R'
AND hp.status = 'A'
AND hca.status = 'A'
AND hps.status = 'A'
AND hcasa.status = 'A'
and dq_pattern(hl.POSTAL_CODE) not in ('uu-dddd')
and hl.country in ('MD')
and hca.account_number not in ('6540888','1374335','57358','58915','3140874','3370379','1374370','57439')
union
SELECT ( select name
from hr_all_organization_units
where organization_id = hcasa.ORG_ID ) ou,
to_number (hca.ACCOUNT_NUMBER) account_number,
to_number (hp.PARTY_NUMBER) party_number,
to_number (hps.PARTY_SITE_NUMBER) party_site_number,
hp.PARTY_NAME,
hp.tax_reference,
hp.jgzz_fiscal_code,
hl.ADDRESS1,
hl.ADDRESS2,
hl.ADDRESS3,
hl.ADDRESS4,
hl.POSTAL_CODE,
dq_pattern(hl.POSTAL_CODE) current_postal_code_pattern,
'ddd' valid_postal_code_patterns,
hl.CITY,
hl.PROVINCE,
hl.COUNTY,
hl.COUNTRY,
hl.STATE,
hcasa.creation_date site_creation_date,
( select user_name
from fnd_user
where user_id = hcasa.created_by ) site_created_by,
hcasa.last_update_date site_last_update_date,
( select user_name
from fnd_user
where user_id = hcasa.last_updated_by ) site_last_updated_by
FROM hz_parties hp,
hz_cust_accounts hca,
hz_cust_acct_sites_all hcasa,
hz_party_sites hps,
hz_locations hl
WHERE hp.PARTY_TYPE = 'ORGANIZATION'
AND hp.PARTY_ID = hca.PARTY_ID
AND hca.CUST_ACCOUNT_ID = hcasa.CUST_ACCOUNT_ID
AND NOT ((hp.status = 'I') and (hca.status = 'I'))
AND hcasa.PARTY_SITE_ID = hps.PARTY_SITE_ID
AND hps.LOCATION_ID = hl.LOCATION_ID
AND hca.customer_type = 'R'
AND hp.status = 'A'
AND hca.status = 'A'
AND hps.status = 'A'
AND hcasa.status = 'A'
and dq_pattern(hl.POSTAL_CODE) not in ('ddd')
and hl.country in ('MG','PG')
and hca.account_number not in ('6540888','1374335','57358','58915','3140874','3370379','1374370','57439')
union
SELECT ( select name
from hr_all_organization_units
where organization_id = hcasa.ORG_ID ) ou,
to_number (hca.ACCOUNT_NUMBER) account_number,
to_number (hp.PARTY_NUMBER) party_number,
to_number (hps.PARTY_SITE_NUMBER) party_site_number,
hp.PARTY_NAME,
hp.tax_reference,
hp.jgzz_fiscal_code,
hl.ADDRESS1,
hl.ADDRESS2,
hl.ADDRESS3,
hl.ADDRESS4,
hl.POSTAL_CODE,
dq_pattern(hl.POSTAL_CODE) current_postal_code_pattern,
'uuu_dddd' valid_postal_code_patterns,
hl.CITY,
hl.PROVINCE,
hl.COUNTY,
hl.COUNTRY,
hl.STATE,
hcasa.creation_date site_creation_date,
( select user_name
from fnd_user
where user_id = hcasa.created_by ) site_created_by,
hcasa.last_update_date site_last_update_date,
( select user_name
from fnd_user
where user_id = hcasa.last_updated_by ) site_last_updated_by
FROM hz_parties hp,
hz_cust_accounts hca,
hz_cust_acct_sites_all hcasa,
hz_party_sites hps,
hz_locations hl
WHERE hp.PARTY_TYPE = 'ORGANIZATION'
AND hp.PARTY_ID = hca.PARTY_ID
AND hca.CUST_ACCOUNT_ID = hcasa.CUST_ACCOUNT_ID
AND NOT ((hp.status = 'I') and (hca.status = 'I'))
AND hcasa.PARTY_SITE_ID = hps.PARTY_SITE_ID
AND hps.LOCATION_ID = hl.LOCATION_ID
AND hca.customer_type = 'R'
AND hp.status = 'A'
AND hca.status = 'A'
AND hps.status = 'A'
AND hcasa.status = 'A'
and dq_pattern(hl.POSTAL_CODE) not in ('uuu_dddd')
and hl.country in ('MT')
union
SELECT ( select name
from hr_all_organization_units
where organization_id = hcasa.ORG_ID ) ou,
to_number (hca.ACCOUNT_NUMBER) account_number,
to_number (hp.PARTY_NUMBER) party_number,
to_number (hps.PARTY_SITE_NUMBER) party_site_number,
hp.PARTY_NAME,
hp.tax_reference,
hp.jgzz_fiscal_code,
hl.ADDRESS1,
hl.ADDRESS2,
hl.ADDRESS3,
hl.ADDRESS4,
hl.POSTAL_CODE,
dq_pattern(hl.POSTAL_CODE) current_postal_code_pattern,
'uu-dddd' valid_postal_code_patterns,
hl.CITY,
hl.PROVINCE,
hl.COUNTY,
hl.COUNTRY,
hl.STATE,
hcasa.creation_date site_creation_date,
( select user_name
from fnd_user
where user_id = hcasa.created_by ) site_created_by,
hcasa.last_update_date site_last_update_date,
( select user_name
from fnd_user
where user_id = hcasa.last_updated_by ) site_last_updated_by
FROM hz_parties hp,
hz_cust_accounts hca,
hz_cust_acct_sites_all hcasa,
hz_party_sites hps,
hz_locations hl
WHERE hp.PARTY_TYPE = 'ORGANIZATION'
AND hp.PARTY_ID = hca.PARTY_ID
AND hca.CUST_ACCOUNT_ID = hcasa.CUST_ACCOUNT_ID
AND NOT ((hp.status = 'I') and (hca.status = 'I'))
AND hcasa.PARTY_SITE_ID = hps.PARTY_SITE_ID
AND hps.LOCATION_ID = hl.LOCATION_ID
AND hca.customer_type = 'R'
AND hp.status = 'A'
AND hca.status = 'A'
AND hps.status = 'A'
AND hcasa.status = 'A'
and dq_pattern(hl.POSTAL_CODE) not in ('uu-dddd')
and hl.country in ('LV')
and hca.account_number not in ('6540888','1374335','57358','58915','3140874','3370379','1374370','57439')
union
SELECT ( select name
from hr_all_organization_units
where organization_id = hcasa.ORG_ID ) ou,
to_number (hca.ACCOUNT_NUMBER) account_number,
to_number (hp.PARTY_NUMBER) party_number,
to_number (hps.PARTY_SITE_NUMBER) party_site_number,
hp.PARTY_NAME,
hp.tax_reference,
hp.jgzz_fiscal_code,
hl.ADDRESS1,
hl.ADDRESS2,
hl.ADDRESS3,
hl.ADDRESS4,
hl.POSTAL_CODE,
dq_pattern(hl.POSTAL_CODE) current_postal_code_pattern,
'uudddd' valid_postal_code_patterns,
hl.CITY,
hl.PROVINCE,
hl.COUNTY,
hl.COUNTRY,
hl.STATE,
hcasa.creation_date site_creation_date,
( select user_name
from fnd_user
where user_id = hcasa.created_by ) site_created_by,
hcasa.last_update_date site_last_update_date,
( select user_name
from fnd_user
where user_id = hcasa.last_updated_by ) site_last_updated_by
FROM hz_parties hp,
hz_cust_accounts hca,
hz_cust_acct_sites_all hcasa,
hz_party_sites hps,
hz_locations hl
WHERE hp.PARTY_TYPE = 'ORGANIZATION'
AND hp.PARTY_ID = hca.PARTY_ID
AND hca.CUST_ACCOUNT_ID = hcasa.CUST_ACCOUNT_ID
AND NOT ((hp.status = 'I') and (hca.status = 'I'))
AND hcasa.PARTY_SITE_ID = hps.PARTY_SITE_ID
AND hps.LOCATION_ID = hl.LOCATION_ID
AND hca.customer_type = 'R'
AND hp.status = 'A'
AND hca.status = 'A'
AND hps.status = 'A'
AND hcasa.status = 'A'
and dq_pattern(hl.POSTAL_CODE) not in ('uudddd')
and hl.country in ('AZ','BN')
and hca.account_number not in ('6540888','1374335','57358','58915','3140874','3370379','1374370','57439')
union
SELECT ( select name
from hr_all_organization_units
where organization_id = hcasa.ORG_ID ) ou,
to_number (hca.ACCOUNT_NUMBER) account_number,
to_number (hp.PARTY_NUMBER) party_number,
to_number (hps.PARTY_SITE_NUMBER) party_site_number,
hp.PARTY_NAME,
hp.tax_reference,
hp.jgzz_fiscal_code,
hl.ADDRESS1,
hl.ADDRESS2,
hl.ADDRESS3,
hl.ADDRESS4,
hl.POSTAL_CODE,
dq_pattern(hl.POSTAL_CODE) current_postal_code_pattern,
'uu-ddddd' valid_postal_code_patterns,
hl.CITY,
hl.PROVINCE,
hl.COUNTY,
hl.COUNTRY,
hl.STATE,
hcasa.creation_date site_creation_date,
( select user_name
from fnd_user
where user_id = hcasa.created_by ) site_created_by,
hcasa.last_update_date site_last_update_date,
( select user_name
from fnd_user
where user_id = hcasa.last_updated_by ) site_last_updated_by
FROM hz_parties hp,
hz_cust_accounts hca,
hz_cust_acct_sites_all hcasa,
hz_party_sites hps,
hz_locations hl
WHERE hp.PARTY_TYPE = 'ORGANIZATION'
AND hp.PARTY_ID = hca.PARTY_ID
AND hca.CUST_ACCOUNT_ID = hcasa.CUST_ACCOUNT_ID
AND NOT ((hp.status = 'I') and (hca.status = 'I'))
AND hcasa.PARTY_SITE_ID = hps.PARTY_SITE_ID
AND hps.LOCATION_ID = hl.LOCATION_ID
AND hca.customer_type = 'R'
AND hp.status = 'A'
AND hca.status = 'A'
AND hps.status = 'A'
AND hcasa.status = 'A'
and dq_pattern(hl.POSTAL_CODE) not in ('uu-ddddd')
and hl.country in ('LT')
and hca.account_number not in ('6540888','1374335','57358','58915','3140874','3370379','1374370','57439')
union
select null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null
from dual
order by 18