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

Home -> Community -> Usenet -> c.d.o.misc -> Re: How to put a Varchar into a Number?

Re: How to put a Varchar into a Number?

From: Elrond <elrond_at_icn.pl>
Date: Wed, 9 Feb 2000 17:15:11 +0100
Message-ID: <87s50v$5o9$1@helios.man.lublin.pl>


Hmmmmmm it's very interesting because the folloving piece of code declare
 my_char varchar2(10);
 my_val number;
begin
 my_char:='006.100';
 message(to_number(replace(my_char,'.'))/5); end;
gives 1220 - and it's OK.
maciej myrcha
"Ken Sproule" <kenmn_at_tds.net> wrote in message news:iv23as82cl3t3ld7evrqt9shfmj5gt5334_at_4ax.com...
> On Wed, 09 Feb 2000 13:48:49 +0100, Pierre Charpenay
> <pcharpenay_at_unilog.fr> wrote:
>
> >
> >
> >Ken Sproule wrote :
> >
> >>
> >> DECLARE
> >> MyNum NUMBER(20,2);
> >> MyVar VARCHAR2(20);
> >> CURSOR test_cur is select * from XXXX;
> >> test_val test_cur%ROWTYPE;
> >>
> >> BEGIN
> >> Open test_cur;
> >> Fetch test_cur into test_val;
> >> -- test_val.cost is a a VARCHAR2 with this in it =è '006.100'
> >> MyVar := test_val.cost ;
> >> REPLACE( MyVar . '.' );
> >
> >What is this ? (equivalent for MyVar=replace(MyVar, '.') (remove the
> >point) ? Are you sure of the result ?
>
> Yes, this gives the number of nickles in a value that is divisible by
> 5.
> >
> >>
> >> MyNum := MyVar; -- *********** Blows here
> >
> >If MyVar is correct, the to_number() function must work.
>
> MyNum := to_number(MyVar); does not work. what will work but is not
> the answer to the problem is this:
>
> update Table_Named_Test set test_cur.SomeNUMBERcolumn = to_number(
> replace( MyVar , '.')) / 5 where ....... ;
>
> The problem seems to be that Oracle is not converting things when the
> variable is DECLARED in the trigger, but it does if the conversion is
> done directly to a REAL Table's column.
>
> How do I do this to a DECLARED variable like MyNum above?
>
> >
> >>
> >> END;
> >
> >Bye.
>
>
>
> Ken Sproule
> kenmn_at_tds.net
Received on Wed Feb 09 2000 - 10:15:11 CST

Original text of this message

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