Můžete použít korelovaný hierarchický dotaz:
SELECT t.id, r.COLUMN_VALUE, t.cnt
FROM table_name t
CROSS JOIN
TABLE(
CAST(
MULTISET(
SELECT LEVEL
FROM DUAL
CONNECT BY LEVEL <= t.cnt
)
AS SYS.ODCINUMBERLIST
)
) r;
nebo rekurzivní klauzule o faktoringu dílčích dotazů:
WITH row_generator ( id, lvl, cnt ) AS (
SELECT id, 1, cnt
FROM table_name
UNION ALL
SELECT id, lvl + 1, cnt
FROM row_generator
WHERE lvl < cnt
)
SELECT *
FROM row_generator
ORDER BY id, lvl
Takže pro testovací data:
CREATE TABLE table_name ( ID, cnt ) AS
SELECT 'A', 12 FROM DUAL UNION ALL
SELECT 'B', 138 FROM DUAL
Obě tato řešení by vypsala:
ID | COLUMN_VALUE | CNT :- | -----------: | --: A | 1 | 12 A | 2 | 12 A | 3 | 12 ... A | 10 | 12 A | 11 | 12 A | 12 | 12 B | 1 | 138 B | 2 | 138 B | 3 | 138 B | 4 | 138 ... B | 136 | 138 B | 137 | 138 B | 138 | 138
db<>zde hrajte