I have a table with data like below
Column A Column B
-------------------------
1 POW
2 POW
1 POWPRO
1 PRO
2 PRO
1 PROUTL
1 TNEUTL
1 UTL
1 UTLTNE
And I need output like below
Output
Column A Column B
1,2 POW,POWPRO,PRO,PROUTL,TNEUTL,UTL,UTLTNE
I tried below query. But the output is different.
select dbms_lob.substr( ltrim(REGEXP_REPLACE(REPLACE(
REPLACE(
XMLAGG(
XMLELEMENT("A",COLUMN_A )
ORDER BY COLUMN_A).getClobVal(),
'<A>',','),
'</A>',' '),'([^,]+)(,\1)+', '\1'),
dbms_lob.substr( ltrim(REGEXP_REPLACE(REPLACE(
REPLACE(
XMLAGG(
XMLELEMENT("A",COLUMN_B )
ORDER BY COLUMN_B).getClobVal(),
'<A>',','),
'</A>',' '),'([^,]+)(,\1)+', '\1') from table_name
But the output is
Column A Column B
-------------------------------------------------
1,2 POW ,POWPRO ,PROUTL ,TNEUTL ,UTLTNE
I want to use only the regexp_replace to search the pattern. Please help me out.