Monday 3 March 2014

Splitting String Using Oracle SQL 9i

 SELECT TRIM( SUBSTR ( txt
                     , INSTR (txt, ',', 1, level ) + 1
                     , INSTR (txt, ',', 1, level+1) - INSTR (txt, ',', 1, level) -1
                     )
            )
         AS token
   FROM ( SELECT ','||:in_string||',' AS txt  FROM dual )
 CONNECT BY level <= LENGTH(txt)-LENGTH(REPLACE(txt,',',''))-1

Example
-------
If value of in_string is entered as
7890,345,567,123,408

Output Is

TOKEN
======
7890
345
567
123
408


Thanks
Amar Alam

0 comments:

Post a Comment