Anda dapat menggunakan kueri hierarkis yang berkorelasi:
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;
atau klausa pemfaktoran sub-kueri rekursif:
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
Jadi untuk data pengujian:
CREATE TABLE table_name ( ID, cnt ) AS
SELECT 'A', 12 FROM DUAL UNION ALL
SELECT 'B', 138 FROM DUAL
Kedua solusi ini akan menghasilkan:
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<>main biola di sini