This is a sub-question of the following: How to unfold the results of an Oracle query based on the value of a column
Instead of simply unfolding I want to also add an ID column that increments and makes each row unique.
So this table:
| col1 | col2 |
|---|---|
| a | 2 |
| b | 3 |
| c | 1 |
Should return this:
| col1 | col2 | col3 |
|---|---|---|
| a | 2 | 1 |
| a | 2 | 2 |
| b | 3 | 1 |
| b | 3 | 2 |
| b | 3 | 3 |
| c | 1 | 1 |
I want to work of the correlated hierarchical query answer by MT0:
SELECT col1, col2
FROM test t,
TABLE(
CAST(
MULTISET(
SELECT LEVEL
FROM DUAL
CONNECT BY LEVEL <= t.col2
)
AS SYS.ODCINUMBERLIST
)
)
A basic self join should suffice here:
Demo