Advertisement
Quantos

listagg all the things

Mar 6th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 2.08 KB | None | 0 0
  1. SELECT DISTINCT hp.party_name,(SELECT hp3.party_name
  2.           FROM hz_parties hp3,
  3.                hz_party_relationship_v hprv
  4.           WHERE hp3.party_id = hprv.subject_id
  5.           AND hprv.party_id = hp2.party_id) "CONTACT",
  6.           (SELECT NVL2(listagg(hcp2.phone_number, ', ') within GROUP (ORDER BY hcp2.phone_number), listagg(hcp2.phone_country_code || '-' || hcp2.phone_area_code || '-' || hcp2.phone_number, ', ') within GROUP (ORDER BY hcp2.phone_country_code || '-' || hcp2.phone_area_code || '-' || hcp2.phone_number), NULL)
  7.             FROM hz_contact_points hcp2
  8.             WHERE hcp2.owner_table_id = hp2.party_id AND hcp2.owner_table_name = 'HZ_PARTIES'
  9.           ) phone_numbers_agg,
  10.           (SELECT listagg(hcp2.email_address, ', ') within GROUP (ORDER BY hcp2.email_address)
  11.             FROM hz_contact_points hcp2
  12.             WHERE hcp2.owner_table_id = hp2.party_id AND hcp2.owner_table_name = 'HZ_PARTIES'
  13.           ) email_addresses_agg
  14.           FROM hz_parties hp
  15.        inner join hz_party_sites hps ON hps.party_id = hp.party_id
  16.        inner join hz_cust_accounts hca ON hca.party_id = hp.party_id
  17.        inner join hz_cust_acct_sites_all hcasa ON hcasa.cust_account_id = hca.cust_account_id AND hcasa.party_site_id = hps.party_site_id
  18.        inner join hz_locations hl ON hl.location_id = hps.location_id
  19.        inner join hz_cust_account_roles hcar ON hcar.cust_account_id = hca.cust_account_id AND hcar.cust_acct_site_id = hcasa.cust_acct_site_id
  20.        inner join hz_parties hp2 ON hp2.party_id = hcar.party_id
  21.        inner join hz_cust_site_uses_all hcsua ON hcsua.cust_acct_site_id = hcasa.cust_acct_site_id
  22.        inner join hz_contact_points hcp ON hcp.owner_table_id = hp2.party_id AND hcp.owner_table_name = 'HZ_PARTIES'
  23.         WHERE 1=1
  24.         AND hcp.status = 'A'
  25.          AND hca.status = 'A'
  26.          AND hp.status = 'A'
  27.          AND hcasa.status = 'A'
  28.          AND hps.status = 'A'
  29.          AND hcar.status = 'A'
  30.          AND hca.account_number = 18751
  31.          AND hcsua.status = 'A'
  32.          AND hcsua.org_id IN ('115') -- specify organization ids
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement