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幫助 –