clicksor ad

Thursday, July 08, 2010

Extract Numbers from a given string

select NUM from
(select
Substr('22,23,24,san,35',instr(','||'22,23,24,san,35',',',1,rownum)
,instr(','||'22,23,24,san,35',',',1,rownum+1)-instr(','||'22,23,24,san,35',',',1,rownum)-1)
NUM
from all_objects
where rownum <= (select length('22,23,24,san,35') -
length(TRANSLATE('22,23,24,san,35',' ,',' ')) from
dual)
union all
select
substr('22,23,24,san,35',instr('22,23,24,san,35',',',-1)+1)
from dual ) a
where length(translate(NUM,'*0123456789','*')) IS
NULL;

The above query helps u to extract all the numbers
from the given string.
If the string is '22,23,24,san,35'
the result will be,

22
23
24
35

No comments: