Sunday, February 12, 2006

Strip out the number from a string

select result
from
(
select level, replace(sys_connect_by_path(x, '/'), '/') result
from
(select rownum lvl, x from (select level lvl, substr('XYZabcd1234.34efEFGgh', level, 1) x
from dual connect by 1 = 1 and level <= length('XYZabcd1234.34efEFGgh'))
where x between '0' and '9' or x = '.')
connect by prior lvl = lvl -1
start with lvl = 1
order by level desc
)
where rownum < 2

RESULT
---------
1234.34

2 comments:

Huiming Li said...
This comment has been removed by a blog administrator.
Huiming Li said...

This is only usefule when you have a NVARCHAR2 string which you can not enumerate. If you have only English, then simple replace will do.