| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
|  |  | |||
Home -> Community -> Mailing Lists -> Oracle-L -> Re: Can TO_NUMBER Do This?
The following works:
select to_number(decode(substr(f1, 1, 1), '(', '-' || substr(f1, 2,
length(f1) - 2), f1));
for exaple:
SQLWKS> declare f1 varchar2(30);
     2> lOut number;
     3> lOutS varchar2(30);
     4> begin
     5> f1 := '12345.678';
     6> select to_number(decode(substr(f1, 1), '(', '-' || substr(f1, 2,
length(f1) - 2), f1)) INTO lOut FROM dual;
     7> dbms_output.put_line('POSITIVE:');
     8> dbms_output.put_line(lOut);
     9> f1 := '(12345.678)';
    11> dbms_output.put_line('NEGATIVE:');
    12> dbms_output.put_line(lOut);
    13> end;
    14> /
> Against the repeated urging of the DBA (me), a developer
> insisted on creating all the numeric columns of his new
> appliction's tables as VARCHAR2.  (Don't ask me why!  I've
> explained it to him several times to no avail.)
>
> Problem
> --------
> Negative values are represented in the tables with parenthesis
> (e.g., '(34,989.89)').  He needs to convert these character
> values to numeric so he can do some math.
>
> I know you can parenthesize values when doing a TO_CHAR like
> this:
>    select to_char(f1,'999D99PR') from test where f1=-123.45
>
>    TO_CHAR(
>    --------
>    <123.45>
>
> However, if this doesn't appear to work with the to_number
> function, at least in my case.
>
> Any ideas how to convert at string like '(1,234.87)' to a
> numeric value?
>
> -Ed
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Mail - Free email you can access from anywhere!
> http://mail.yahoo.com/
> --
> Author: Ed Bittel
>   INET: ebittel_at_yahoo.com
>
> 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
Received on Mon Aug 28 2000 - 14:06:57 CDT
|  |  |