1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 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 ; |
1 2 3 4 | 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) |