Я решил ее, заменив sys.DBMSOUTPUT_LINESARRAY
на XMLAGG
и применив к ней regexp_replace
.
SELECT Trim(owner_dsply_nm) AS CASE_OWNER
,count(distinct case_intrl_id) AS NUMBER_OF_CASES_WORKED
--,cast(collect(distinct case_intrl_id) AS sys.DBMSOUTPUT_LINESARRAY) AS CASE_ID
,regexp_replace((RTRIM(XMLAGG(XMLELEMENT(E,case_intrl_id,',').EXTRACT('//text()') ORDER BY case_intrl_id).GetClobVal(),',')),'([^,]+)(,\1)+', '\1') AS CASE_ID
,Trim(status_nm) AS STATUS_VALUE
,To_char(action_ts, 'MON.DD.YYYY') AS STATUS_CHANGE_DATE
,To_char(action_ts - 7 / 24, 'IYYY') AS STATUS_CHANGE_YEAR
,To_char(action_ts - 7 / 24, 'IW') AS STATUS_CHANGE_WEEK
FROM KDD_CASE_ACTIONS a
join KDD_STATUS s
ON a.status_cd = s.status_cd
join KDD_REVIEW_OWNER r
ON r.owner_seq_id = a.action_by_id
WHERE a.status_cd NOT IN ( 'SBTMNEW', 'NW', 'SB01NEW' )
AND Trim(UPPER(owner_dsply_nm)) NOT IN ('SYSTEM')
GROUP BY Trim(owner_dsply_nm)
,Trim(status_nm)
,To_char(action_ts, 'MON.DD.YYYY')
,To_char(action_ts - 7 / 24, 'IYYY')
,To_char(action_ts - 7 / 24, 'IW')
ORDER BY STATUS_CHANGE_YEAR DESC
,STATUS_CHANGE_WEEK DESC
,CASE_OWNER;