I have a hyphen separated column containing names. I want to split this column into one single name rows.
I am using the following sql :
for t_cur in (select id, names str from table where names is not null) loop
insert into inv value (select id,SPLIT_VALUES,'TOT' from ( select t_cur.id, trim(REGEXP_SUBSTR (t_cur.STR, '[^-]+', 1, LEVEL)) SPLIT_VALUES FROM dual
CONNECT BY LEVEL <= (SELECT LENGTH (REPLACE (t_cur.STR, ',', NULL)) FROM dual
) ) where SPLIT_VALUES is not null) ;
end loop;
end;
The issue is that some names are composed. for example i could have :
Firstname1-secondname1 lastname1 - Firstname2 lastname2 - Firstname3 Lastname3
in this example i am having as a result :
Firstname1
secondname1 lastname1
Firstname2 lastname2
Firstname3 Lastname3
can you help me with the right regular expression to use to have this result :
Firstname1-secondname1 lastname1
Firstname2 lastname2
Firstname3 Lastname3
the solution should be to check char until (space+hypehen) and not just (hyphen)
Thanks !