I have a requirement to remove duplicate values from a comma separated string.
Input String: a,a,a,b,c,a,b
Expected output: a,b,c
What I have tried:
with ct(str) as(
select 'a,a,a,b,c,a,b' from dual
)
select REGEXP_REPLACE(str,'([^,]*)(,\1)+($|,)','\1\3') col from ct
Output: a,b,c,a,b
The above query can remove repetitive characters which are consecutive.
I know that the above requirement can be solved by creating a table out of the comma separated values and do a listagg on the distinct values.
Is it possible to achieve the above requirement using a single regex statement?.