For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!
Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.
str := 'abcd,123,defoifcd,87765'
SELECT REGEXP_SUBSTR (str, '[^,]+', 1, 1) AS part_1 , REGEXP_SUBSTR (str, '[^,]+', 1, 2) AS part_2 , REGEXP_SUBSTR (str, '[^,]+', 1, 3) AS part_3 , REGEXP_SUBSTR (str, '[^,]+', 1, 4) AS part_4 FROM table_x ;
SELECT RTRIM (REGEXP_SUBSTR (str, '[^,]*,', 1, 1), ',') AS part_1 , RTRIM (REGEXP_SUBSTR (str, '[^,]*,', 1, 2), ',') AS part_2 , RTRIM (REGEXP_SUBSTR (str, '[^,]*,', 1, 3), ',') AS part_3 , LTRIM (REGEXP_SUBSTR (str, ',[^,]*', 1, 3), ',') AS part_4 FROM table_x ;
SQL> ed Wrote file afiedt.buf 1 with t as (select 'abcd,123,defoifcd,87765' as str from dual) 2 -- 3 select level as n, regexp_substr(str,'[^,]+',1,level) as val 4 from t 5* connect by regexp_substr(str,'[^,]+',1,level) is not null SQL> / N VAL -- ----------------------- 1 abcd 2 123 3 defoifcd 4 87765 SQL> ed Wrote file afiedt.buf 1 with t as (select 'abcd,123,defoifcd,87765' as str from dual) 2 -- 3 select max(decode(level,1,regexp_substr(str,'[^,]+',1,level))) as val1 4 ,max(decode(level,2,regexp_substr(str,'[^,]+',1,level))) as val2 5 ,max(decode(level,3,regexp_substr(str,'[^,]+',1,level))) as val3 6 ,max(decode(level,4,regexp_substr(str,'[^,]+',1,level))) as val4 7 ,max(decode(level,5,regexp_substr(str,'[^,]+',1,level))) as val5 8 ,max(decode(level,6,regexp_substr(str,'[^,]+',1,level))) as val6 9 ,max(decode(level,7,regexp_substr(str,'[^,]+',1,level))) as val7 10 ,max(decode(level,8,regexp_substr(str,'[^,]+',1,level))) as val8 11 ,max(decode(level,9,regexp_substr(str,'[^,]+',1,level))) as val9 12 ,max(decode(level,10,regexp_substr(str,'[^,]+',1,level))) as val10 13 from t 14* connect by regexp_substr(str,'[^,]+',1,level) is not null SQL> / VAL1 VAL2 VAL3 VAL4 VAL5 VAL6 VAL7 VAL8 VAL9 VAL10 ----------------------- ----------------------- ----------------------- ----------------------- ----------------------- ----------------------- ----------------------- ----------------------- ----------------------- ----------------------- abcd 123 defoifcd 87765 SQL>
with t as ( select 'abcd,123,defoifcd,87765' as str from dual ) select extractvalue(value(x), '/b') x from t, table( xmlsequence( xmltype('<a><b>' || replace(str, ',', '</b><b>') || '</b></a>' ).extract('/*/*') ) ) x / X ---------- abcd 123 defoifcd 87765 SQL>
LTRIM (REGEXP_SUBSTR (str, ',[^,]*', 1, 3), ',') AS part_4
SQL> ed Wrote file afiedt.buf 1 with t as (select 'This is some sample text that needs splitting into words' as txt from dual) 2 select x.* 3 from t 4 ,xmltable('x/y' 5 passing xmltype('<x><y>'||replace(t.txt,' ','</y><y>')||'</y></x>') 6 columns word varchar2(20) path '.' 7* ) x SQL> / WORD -------------------- This is some sample text that needs splitting into words 10 rows selected.
, RTRIM (REGEXP_SUBSTR (str, '[^,]*,', 1, N), ',') AS part_N
, LTRIM (REGEXP_SUBSTR (str, ',[^,]*', 1, N-1), ',') AS part_N
SQL> ed Wrote file afiedt.buf 1 with t as (select 'This is just a test' as txt from dual) 2 -- 3 -- end of test data 4 -- 5 select trim(sys_connect_by_path(word, ' ')) as word_phrase 6 from ( 7 select x.* 8 from t 9 ,xmltable('x/y' 10 passing xmltype('<x><y>'||replace(t.txt,' ','</y><y>')||'</y></x>') 11 columns rn for ordinality 12 ,word varchar2(20) path '.' 13 ) x 14 ) 15 where level <= 3 16 connect by rn = prior rn + 1 17* order by level, rn SQL> / WORD_PHRASE -------------------------------------------------------------------------------------------- This is just a test This is is just just a a test This is just is just a just a test 12 rows selected.