WITH t AS ( SELECT 'A' cd, 10 unit, 50 cnt FROM dual UNION ALL SELECT 'B', 10, 45 FROM dual UNION ALL SELECT 'C', 10, 15 FROM dual UNION ALL SELECT 'D', 20, 50 FROM dual ) SELECT cd , unit , cnt , LEAST(cnt - unit*(lv-1), unit) FROM t , (SELECT LEVEL lv FROM dual CONNECT BY LEVEL <= 99) WHERE lv <= CEIL(cnt / unit) ORDER BY cd, lv ;
SELECT prod, val1, val2 , LEAST(val1, val2 - ((LEVEL -1) * val1)) FROM (SELECT 'A' prod, 10 val1, 15 val2 FROM dual) CONNECT BY LEVEL <= CEIL(val2 / val1)