select listagg('#'||min(no)||'-#'||max(no),',') within group (order by min(lv)) txt from ( select to_number(regexp_substr(txt,'[^,]+',1,level)) no, level lv from (select '1,2,3,4,5,6,7,8,9,11,12,13,15,16,17,18,19,20,21,22,23,24,25' txt from dual) connect by level <= regexp_count(txt,',') + 1 ) group by lv-no