vendredi 3 avril 2015

SQL for splitting a single row data into multiple rows based on character

So far I have written a query that splits the first row into multiple rows but the result for the following N rows will be N rows returning null values.


Here is the scenario.



select address from sample;


Which would return following 4 rows,



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


When tried to split each row into multiple rows using the following query,



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
;


The following values will be returned.



Stack Overflow
is a
question and
answer site
(null)
(null)
(null)


Why cant I get the results for all rows?


Aucun commentaire:

Enregistrer un commentaire