WITH t AS ( SELECT 1 idx, '1' v FROM dual UNION ALL SELECT 2, '1,10' FROM dual UNION ALL SELECT 3, '1,2' FROM dual UNION ALL SELECT 4, '1,2,3' FROM dual UNION ALL SELECT 5, '1,2,3,4' FROM dual UNION ALL SELECT 6, '1,2,3,4,5' FROM dual UNION ALL SELECT 7, '1,2,3,4,5,6' FROM dual UNION ALL SELECT 8, '1,2,3,4,5,6,7' FROM dual UNION ALL SELECT 9, '1,2,3,4,5,6,7,8' FROM dual UNION ALL SELECT 10, '1,2,3,4,5,6,7,8,9' FROM dual UNION ALL SELECT 11, '2,3,4,5,6,7' FROM dual UNION ALL SELECT 12, '2,3,4,6,20' FROM dual UNION ALL SELECT 13, '2,3,4,6,7' FROM dual UNION ALL SELECT 14, '2,3,4,6,7,8' FROM dual UNION ALL SELECT 15, '2,3,4,6,8' FROM dual UNION ALL SELECT 16, '2,3,4,6,9' FROM dual UNION ALL SELECT 17, '2,3,4,7' FROM dual ) SELECT lv , COUNT(idx) cnt FROM (SELECT LEVEL lv FROM dual CONNECT BY LEVEL <= 20) a LEFT OUTER JOIN t b ON INSTR(','||v||',', ','||lv||',') > 0 GROUP BY lv ORDER BY lv ;