I have existing PL/SQL code with formatting for the client process that is doing a cursor with case for a join on multiple tables using row_number () over partition by. It was all fine, till we noticed that if a certain record had multiple contact information on it, the formatting the way it is set, instead of including all the contacts as part of the same record, it is outputting the contacts as different rows for the same customer. How do i tweak the cursor to make it appear as one record with all contact information(s)? Expected :
+-------+-----------+------------+-------------------+-------------+-----------+-------------------+------------+
| ID | NAME | CONTACT1 | EMAIL1 | PHONE1 | CONTACT2 | EMAIL2 | PHONE2 |
+-------+-----------+------------+-------------------+-------------+-----------+-------------------+------------+
| 50000 | Customer1 | Rodney | Rodney@gmail.com | 1112223333 | Billy | Billy@hotmail.com | 4445556666 |
+-------+-----------+------------+-------------------+-------------+-----------+-------------------+------------+
Instead of :
+-------+------------+-----------+-------------------+-------------+
| ID | NAME | CONTACT1 | EMAIL1 | PHONE1 |
+-------+------------+-----------+-------------------+-------------+
| 50000 | Customer1 | Rodney | Rodney@gmail.com | 1112223333 |
| 50000 | Customer1 | Billy | Billy@hotmail.com | 4445556666 |
+-------+------------+-----------+-------------------+-------------+
The code is as follows :
cursor c1 is
select case rn1 when 1 then "TypeOfContract" end "TypeOfContract",
case rn1 when 1 then "ContractNumber" end "ContractNumber",
case rn1 when 1 then "ClientName" end "ClientName",
"AdminName",
--case rn1 when 1 then "AdminName" end "AdminName",
--case rn1 when 1 then "TechnicalName" end "TechnicalName",
"TechnicalName",
--case rn1 when 1 then "DayToDayName" end "DayToDayName",
"DayToDayName",
case rn2 when 1 then "ServiceName" end "ServiceName",
case rn2 when 1 then "ServiceNumber" end "ServiceNumber",
"SubserviceName",
"SubserviceNumber",
"Map",
"VolumeOfFilesMessages",
"VolumeOfPayments",
"DollarAmountOfPayments"
from (select "TypeOfContract","ContractNumber","ClientName","AdminName","TechnicalName","DayToDayName",
"ServiceName","ServiceNumber","SubserviceName","SubserviceNumber","Map","VolumeOfFilesMessages","VolumeOfPayments","DollarAmountOfPayments",
row_number() over (partition by "TypeOfContract","ContractNumber","ClientName","AdminName","TechnicalName","DayToDayName"
order by "ServiceName","ServiceNumber") rn1,
row_number() over (partition by "TypeOfContract","ContractNumber","ClientName"/*,"AdminName","TechnicalName","DayToDayName"*/,"ServiceName","ServiceNumber"
order by null) rn2
from (
SELECT DISTINCT
case when tctc_cntipcli='C' then 'Host2Host' when tctc_cntipcli='L' then 'File Transfer Services' when tctc_cntipcli='I' then 'Integrated Payables' when tctc_cntipcli='D' then 'Data Exchange'
when tctc_cntipcli='V' then 'Vendor' when tctc_cntipcli='E' then 'External Bank'end as "TypeOfContract" ,
tctc_cncclipu as "ContractNumber",
regexp_replace(tctc_cndocidc, '[^[:alnum:]'' '']', NULL) as "ClientName",
case when tcct_cncctto = 'A' then (select trim(tcct_cnctname)||trim(tcct_cnemail)||trim(tcct_cnphone) from dual) end as "AdminName" ,
case when tcct_cncctto = 'T' then (select trim(tcct_cnctname)||trim(tcct_cnemail)||trim(tcct_cnphone) from dual) end as "TechnicalName",
case when tcct_cncctto = 'D' then (select trim(tcct_cnctname)||trim(tcct_cnemail)||trim(tcct_cnphone) from dual) end as "DayToDayName",
tsrv_cndesser as "ServiceName",
texe_cnfuncid as "ServiceNumber",
tsrs_cnsubsdc as "SubserviceName",
texe_cnsubser as "SubserviceNumber",
tmap_cndesc as "Map"
from service.kndtctc, service.kndtexe, service.kndtscm, service.kndtsrv, service.kndtsrs, service.kndtmap, service.kndtcct
where tctc_cncclipu = texe_cncclipu
and texe_cnfuncid = tsrv_cncveser
and texe_cnfuncid = tsrs_cncveser
and texe_cnsubser = tsrs_cnsubser
and texe_cncclipu = tscm_cncontra
and tscm_cnmapco = tmap_cnmapco
and tscm_cnservic = tsrv_cncveser
and tscm_cnsubser = tsrs_cnsubser
and texe_cncclipu = tcct_cncclipu
and tscm_cncontra = tcct_cncclipu
and tctc_cnestado in ('01', '03')
and texe_cnestado in ('01', '03')
and tsrv_cnestado in ('01', '03')
and tsrs_cnestado in ('01', '03')
and tscm_cnestado in ('01', '03')
and tmap_cnestado in ('01', '03')
order by tctc_cncclipu
)
)
;
Appreciate any help the community can provide!