Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: Conversion of a varchar2 to a number

Re: Conversion of a varchar2 to a number

From: Rajagopal Venkataramany <rajagopalvr_at_excite.com>
Date: Thu, 14 Dec 2000 13:25:05 -0800 (PST)
Message-Id: <10710.124630@fatcity.com>


David,

  This is my suggestion :

(vrr is the table with w_char varchar2(10))

  select * from vrr;

W_CHAR



abc
1abc
123

select w_char, to_number(w_char)
from vrr
where length(w_char) =
length(translate(upper(w_char),'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', '0123456789'))
/
W_CHAR TO_NUMBER(W_CHAR)

-------------------- -----------------
123                                123

You may have to modify the code to include the ( , ) and - characters that u may have in a phone number format.

 Let me know if this works for u...

Regards
Rajagopal Venkataramany

On Wed, 13 Dec 2000 10:45:54 -0800, ORACLE-L_at_fatcity.com wrote:

> I have a user that has a phone number field that is stored as
> a varchar2 and some of the data actually has letters in it. When
> he tries to do a TO_NUMBER it fails of course on the records that
> have letters in them.
>
> To perform the conversion I thought using a cursor and handling the
> exceptions would work, but wanted to see if other people had a better
> way of doing this.
>
> Thanks, Dave Turner
> --
> Please see the official ORACLE-L FAQ: http://www.orafaq.com
> --
> Author: David Turner
> INET: turner_at_elvis.mu.org
>
> Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051
> San Diego, California -- Public Internet access / Mailing Lists
> --------------------------------------------------------------------
> To REMOVE yourself from this mailing list, send an E-Mail message
> to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
> the message BODY, include a line containing: UNSUB ORACLE-L
> (or the name of mailing list you want to be removed from). You may
> also send the HELP command for other information (like subscribing).

Regards
Rajagopal Venkataramany



Send a cool gift with your E-Card Received on Thu Dec 14 2000 - 15:25:05 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US