if your version in below 10g then you can try something like this
SQL> with t as(select 'SCOTT,ALLEN,KING,SCOTT'
test_string from dual)
2 select distinct substr(test_string
3 ,decode(level,1,1,instr(test_string,','
,1,level-1)+1)
4 ,decode(level,4,length(test_string),instr(test_string,','
,1,level)-decode(level,1,0,instr(test_string,','
,1,level-1))-1)) from t
5 connect by level<=length(test_string)-length(replace(test_string,','
))+1;
SUBSTR(TEST_STRING,DECODE(LEVEL,1,1,INSTR(TEST_STRING,','
,1,LEVEL-1)+1),DECODE(LEVEL,4,L
----------------------------------------------------------------------------------------
ALLEN
SCOTT
KING
3 rows selected.
Hi,
XMLAGG work in 9i too, you have to only substitute the regexp part in my solution to make it work on 9i
with t as(select 'SCOTT,ALLEN,KING,SCOTT'
test_string from dual)
select distinct
substr(test_string ,decode(level,1,1,instr(test_string,','
,1,level-1)+1)
,decode(level,4,length(test_string),instr(test_string,','
,1,level)-decode(level,1,0,instr(test_string,','
,1,level-1))-1))
from t connect by level<=length(test_string)-length(replace(test_string,','
))+1
/
SUBSTR(TEST_STRING,DEC
----------------------
ALLEN
1 row selected.
SQL> select * from V$version ;
BANNER
----------------------------------------------------------------
Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production
PL/SQL Release 9.2.0.8.0 - Production
CORE 9.2.0.8.0 Production
TNS for
32-bit Windows: Version 9.2.0.8.0 - Production
NLSRTL Version 9.2.0.8.0 - Production
Here is the fix
with t as(select 'SCOTT,ALLEN,KING,SCOTT'
test_string from dual)
, t1 as ( select distinct
substr(test_string ,decode(level,1,1,instr(test_string,','
,1,level-1)+1)
,decode(level,4,length(test_string),instr(test_string,','
,1,level)-decode(level,1,0,instr(test_string,','
,1,level-1))-1))
from t connect by level<=length(test_string)-length(replace(test_string,','
))+1
)
select * from t1
/
SUBSTR(TEST_STRING,DEC
----------------------
ALLEN
KING
SCOTT
3 rows selected.
SS