clear markdown compare help best fiddles feedback dbanow.uk a leap of faith?
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 1305706 fiddles created (20116 in the last week).

CREATE TABLE ListAggTest AS ( SELECT rownum Num1, DECODE(rownum,1,'2',to_char(rownum)) Num2 FROM dual CONNECT BY rownum<=6 ) order by DBMS_RANDOM.VALUE;
6 rows affected
 hidden batch(es)


select * from ListAggTest;
NUM1 NUM2
2 2
6 6
1 2
3 3
5 5
4 4
 hidden batch(es)


SELECT Num1, listagg(Num2,'-') WITHIN GROUP (ORDER BY Num2) OVER () Num2s FROM ListAggTest;
NUM1 NUM2S
2 2-2-3-4-5-6
1 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
 hidden batch(es)


SELECT Num1, RTRIM( REGEXP_REPLACE( (listagg(Num2,'-') WITHIN GROUP (ORDER BY Num2) OVER ()), '([^-]*)(-\1)+($|-)', '\1\3'), '-') Num2s FROM ListAggTest;
NUM1 NUM2S
2 2-3-4-5-6
1 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
 hidden batch(es)