Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrive Only Numeric Fields from a String

Status
Not open for further replies.

himridul

Programmer
Jun 23, 2003
62
US
Hi,

I have a input string . I need only the number from this field using REPLACE or TRANSLATE or any function in the SELECT statement.

eg,

the input string is :
' 1 :: 2 3 Adfre 34 * & )( -= bd '

It should return only the numeric field
12334


I tried with
SELECT TRANSLATE(string,TRANSLATE(string,'0123456789',' '),'') from dual;

-- But it's not working properly.

Any help plz .......

 
Hi,

Try this code,

Code:
select translate('your string', 
                 translate('your string','0123456789', ' ')
                 ' ')
from   dual;

Example with your string
Code:
select translate('  1 ::  2 3 Adfre 34 * & )( -= bd ',
            translate('  1 ::  2 3 Adfre 34 * & )( -= bd ', 
                      '0123456789', 
                      ' '
                      ),
                 ' '
                 )
from   dual;

Tell if it works...

Gunjan
 
Here is code for a generic string conversion:
Code:
SQL> select
  2  (TRANSLATE(
  3  (TRANSLATE(
  4   upper('  1 ::  2 3 Adfre 34 * & )( -= bd '),
  5   ',./;''[]\=-`~!@#$%^&*()_+{}:"<>?ABCDEFGHIJKLMNOPQRSTUVWXYZ ',
  6   '                                                          ')),
  7   '1234567890 ','1234567890')) text
  8  from dual;

TEXT
-----
12334

Beware of false knowledge; it is more dangerous than ignorance. ~George Bernard Shaw
Consultant/Custom Forms & PL/SQL - Oracle 8i & 9i - Windows 2000
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top