Table A
col1 col2
-------------------------------
1 1,2,3
2 1,2,4,5
必需输出
col1 col2
-------------------------
1 1
1 2
1 3
2 1
2 2
2 4
2 5
如何在oracle中获得所需的输出?提前致谢
答案 0 :(得分:0)
这是一个选项:
SQL> with test (col1, col2) as
2 (select 1, '1,2,3' from dual union
3 select 2, '5,6,7,8' from dual
4 )
5 select col1, regexp_substr(col2, '[^,]+', 1, column_value) col2
6 from test,
7 table(cast(multiset(select level from dual
8 connect by level <= regexp_count(col2, ',') + 1)
9 as sys.odcinumberlist))
10 order by col1, 2;
COL1 COL2
---------- -------
1 1
1 2
1 3
2 5
2 6
2 7
2 8
7 rows selected.
SQL>