select regexp_replace(listagg('12345,12345,12345,54321,54321',',')within group (order by 1),
'([^,]+)(,\1)*(,|$)',
'\1\3') as a
from dual;
select regexp_replace(listagg('12345,12345,12345,54321,54321',',')within group (order by 1),
'([^,]+)(,\1)*(,|$)',
'\1\3') as a
from dual;