Paste this into a new question or an answer at dba.stackexchange.com:
<!-- --> > CREATE TABLE ListAggTest AS ( > SELECT rownum Num1, DECODE(rownum,1,'2',to_char(rownum)) Num2 FROM dual > CONNECT BY rownum<=6 > ); > > <pre> 6 rows affected > </pre> <!-- --> > SELECT Num1, listagg(Num2,'-') WITHIN GROUP (ORDER BY NULL) OVER () Num2s > FROM ListAggTest; > > <pre> > NUM1 | NUM2S > ---: | :---------- > 1 | 2-2-3-4-5-6 > 2 | 2-2-3-4-5-6 > 3 | 2-2-3-4-5-6 > 4 | 2-2-3-4-5-6 > 5 | 2-2-3-4-5-6 > 6 | 2-2-3-4-5-6 > </pre> <!-- --> > SELECT Num1, > RTRIM( > REGEXP_REPLACE( > (listagg(Num2,'-') WITHIN GROUP (ORDER BY Num2) OVER ()), > '([^-]*)(-\1)+($|-)', > '\1\3'), > '-') Num2s > FROM ListAggTest; > > <pre> > NUM1 | NUM2S > ---: | :-------- > 1 | 2-3-4-5-6 > 2 | 2-3-4-5-6 > 3 | 2-3-4-5-6 > 4 | 2-3-4-5-6 > 5 | 2-3-4-5-6 > 6 | 2-3-4-5-6 > </pre> *db<>fiddle [here](https://dbfiddle.uk/?rdbms=oracle_11.2&fiddle=c8457f3533808b755c46162d8fe45eb3)*
back to fiddle