0
A
回答
0
0
with src as
(
select '1' col0, '2' col1, 'test1,test2' col2 from dual union all
select '11' col0, '22' col1, 'test11,test22' col2 from dual
)
, explode as
(
select col0
, col1
, regexp_substr(col2, '\w+', 1, 1) as col2_1
, regexp_substr(col2, '\w+', 1, 2) as col2_2
-- if there is more add more...
from src
)
select col0, col1, col2_1 from explode where col2_1 is not null union all
select col0, col1, col2_2 from explode where col2_2 is not null
order by col0, col1, col2_1
;
1 2 test1
1 2 test2
11 22 test11
11 22 test22
五个值的示例:
with src as
(
select '1' col0, '2' col1, 'test1,test2' col2 from dual union all
select '11' col0, '22' col1, 'test11,test22' col2 from dual union all
select '111' col0, '222' col1, 'test31,test32,test33,test34,test35' col2 from dual
)
, explode as
(
select col0
, col1
, regexp_substr(col2, '\w+', 1, 1) as col2_1
, regexp_substr(col2, '\w+', 1, 2) as col2_2
, regexp_substr(col2, '\w+', 1, 3) as col2_3
, regexp_substr(col2, '\w+', 1, 4) as col2_4
, regexp_substr(col2, '\w+', 1, 5) as col2_5
-- if there is more add more...
from src
)
select col0, col1, col2_1, col2_2, col2_3, col2_4, col2_5 from explode where col2_1 is not null union all
select col0, col1, col2_1, col2_2, col2_3, col2_4, col2_5 from explode where col2_2 is not null union all
select col0, col1, col2_1, col2_2, col2_3, col2_4, col2_5 from explode where col2_3 is not null union all
select col0, col1, col2_1, col2_2, col2_3, col2_4, col2_5 from explode where col2_4 is not null union all
select col0, col1, col2_1, col2_2, col2_3, col2_4, col2_5 from explode where col2_5 is not null
order by col0, col1, col2_1, col2_2, col2_3, col2_4, col2_4, col2_5
;
1 2 test1 test2
1 2 test1 test2
11 22 test11 test22
11 22 test11 test22
111 222 test31 test32 test33 test34 test35
111 222 test31 test32 test33 test34 test35
111 222 test31 test32 test33 test34 test35
111 222 test31 test32 test33 test34 test35
111 222 test31 test32 test33 test34 test35
+0
确定THX但有时我在一个行,有时有更多的价值,有时3 5 –
+0
@JohnRambo您必须根据需要多次重复“爆炸”部分中的“regexp_substr”功能。你可以给更多的以防万一... –
+0
是的我明白这个例子,但我nedd动态SQL,但有时用户写2值meybe 6. 2和6是动态值,我现在不用用户写什么:) –
相关问题
- 1. 将SQL Server表定期转储到Oracle表中
- 2. 改变行列
- 3. 运行sql多次改变参数
- 4. 改变天结果一行到周SQL
- 5. 改变行组
- 6. SQL查询改变
- 7. C#改变SQL表
- 8. SQL改变类型
- 9. 改变表SQL PHP
- 10. SQL脚本改变
- 11. 改变SQL限制
- 12. 改变SQL到HQL
- 13. SQL:选择行,其中列值从先前行改变
- 14. SQL错误改变表?
- 15. 改变SQL表添加列
- 16. SQL Server改变计算列
- 17. SQL - 的OleDbCommand不改变SQL参数
- 18. 列变换行SQL
- 19. 的ListView改变行
- 20. 改变行为Angularjs
- 21. QueryTables.Add改变行高
- 22. 改变换行行为
- 23. jQuery的改变DIV ID,运行旧DIV ID执行不改变
- 24. 改变HAVING改变列值
- 25. 动态透视表改变行
- 26. 如何改变插入的行在SQL Server触发
- 27. SQL:添加新行,但改变一个领域
- 28. SQL Server 2008 - 位参数评估改变执行计划
- 29. NSIS 2不能改变mysql的密码/运行SQL脚本
- 30. SQL - 如何在执行INSERT INTO时改变表格?
确定THX非常非常veery帮助 –