DECLARE
CURSOR rsrv_cur
IS
SELECT distinct stg.so_line_id
FROM apps.wwt_xxwms_rsrv_onhand_cnv_stg stg
WHERE 1 = 1
AND stg.source_code = 'VALIDATION_DATA'
--AND stg.s_status_code = 'V'
AND stg.l_source_organization_id = :g_source_organization_id
AND stg.l_dest_organization_id = :g_destination_organization_id
AND stg.lpn IS NULL
AND stg.serial_number IS NOT NULL
AND stg.serial_control_flag = 'Y'
GROUP BY stg.so_line_id,
'SERIAL';
l_rsrv_value VARCHAR2(32767) ;
BEGIN
for rsrv_rec IN rsrv_cur LOOP
dbms_output.put_line ('SO_LINE_ID => '||rsrv_rec.so_line_id);
BEGIN
SELECT
RTRIM (REGEXP_REPLACE ( (LISTAGG (stg.serial_number, ',') WITHIN GROUP (ORDER BY stg.serial_number) ),
'([^,]*)(,\1)+($|,)',
'\1\3'),
',') rsrv_value
INTO l_rsrv_value
FROM apps.wwt_xxwms_rsrv_onhand_cnv_stg stg
WHERE stg.so_line_id = rsrv_rec.so_line_id ;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line ('SO_LINE_ID => '||rsrv_rec.so_line_id||' '||SQLERRM);
SELECT regexp_replace( XMLAGG(XMLELEMENT(E,stg.serial_number||',').EXTRACT('//text()') ).getclobval(),'^,|,$', '') Result
INTO l_rsrv_value
FROM apps.wwt_xxwms_rsrv_onhand_cnv_stg stg
WHERE stg.so_line_id = rsrv_rec.so_line_id ;
dbms_output.put_line ('l_rsrv_value => '||l_rsrv_value);
END ;
END LOOP rsrv_rec;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line ('Error '||SQLERRM);
END;
CURSOR rsrv_cur
IS
SELECT distinct stg.so_line_id
FROM apps.wwt_xxwms_rsrv_onhand_cnv_stg stg
WHERE 1 = 1
AND stg.source_code = 'VALIDATION_DATA'
--AND stg.s_status_code = 'V'
AND stg.l_source_organization_id = :g_source_organization_id
AND stg.l_dest_organization_id = :g_destination_organization_id
AND stg.lpn IS NULL
AND stg.serial_number IS NOT NULL
AND stg.serial_control_flag = 'Y'
GROUP BY stg.so_line_id,
'SERIAL';
l_rsrv_value VARCHAR2(32767) ;
BEGIN
for rsrv_rec IN rsrv_cur LOOP
dbms_output.put_line ('SO_LINE_ID => '||rsrv_rec.so_line_id);
BEGIN
SELECT
RTRIM (REGEXP_REPLACE ( (LISTAGG (stg.serial_number, ',') WITHIN GROUP (ORDER BY stg.serial_number) ),
'([^,]*)(,\1)+($|,)',
'\1\3'),
',') rsrv_value
INTO l_rsrv_value
FROM apps.wwt_xxwms_rsrv_onhand_cnv_stg stg
WHERE stg.so_line_id = rsrv_rec.so_line_id ;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line ('SO_LINE_ID => '||rsrv_rec.so_line_id||' '||SQLERRM);
SELECT regexp_replace( XMLAGG(XMLELEMENT(E,stg.serial_number||',').EXTRACT('//text()') ).getclobval(),'^,|,$', '') Result
INTO l_rsrv_value
FROM apps.wwt_xxwms_rsrv_onhand_cnv_stg stg
WHERE stg.so_line_id = rsrv_rec.so_line_id ;
dbms_output.put_line ('l_rsrv_value => '||l_rsrv_value);
END ;
END LOOP rsrv_rec;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line ('Error '||SQLERRM);
END;