1
到目前爲止,我已經編寫了一個查詢,將第一行拆分爲多行,但以下N行的結果將返回N行,返回空值。用於根據字符將單行數據拆分爲多行的SQL
這是場景。
select address from sample;
這將返回以下4行,
Stack Overflow# is a# question and# answer site
Stack Overflow# is a# question and# answer site
Stack Overflow# is a# question and# answer site
Stack Overflow# is a# question and# answer site
當試圖每一行拆分爲使用下面的查詢多行,
with test as (select address as str from sample)
select regexp_substr (str, '[^#]+', 1, rownum) split
from test
connect by level <= length (regexp_substr (str, '[^#]+', 1, rownum)) + 1
;
以下值將返回
。
Stack Overflow
is a
question and
answer site
(null)
(null)
(null)
爲什麼不能得到所有行的結果?
請爲您正在使用的RDBMS添加標籤。這不是標準的SQL,它需要特定於實現的答案。 – Barmar 2015-04-03 04:30:13
哦!我的錯。它的Oracle – 2015-04-03 05:07:30
我很高興看到字符串拆分問題:-)我一直在回答這個問題的大多數相關的問題。你幾乎接近你想要的輸出,但是你做了兩件事情根本錯誤。查看我的答案瞭解更多詳情。 – 2015-04-03 11:26:28