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

Home -> Community -> Usenet -> c.d.o.tools -> Re: function to get only numbers

Re: function to get only numbers

From: Jim Lyons <jlyons_at_weblyons.com>
Date: 5 Jul 2001 07:59:45 -0700
Message-ID: <e67857c9.0107050659.7f74f1f1@posting.google.com>

"Philippe Makowski" <makowski.philippe_at_wanadoo.fr> wrote in message news:<9i05pr$i8b$1_at_wanadoo.fr>...
> why this function does not compile ?
>
>
> CREATE OR REPLACE FUNCTION char2num (charnum in varchar2) RETURN number IS
> i number;
> digits number;
> current_digit char(1);
> parsechar varchar2;
> BEGIN
> parsechar :='';
> digits := length(charnum);
> for i in 1..digits loop
> current_digit := SUBSTR(charnum, i, 1);
> if current_digit in ('0','1','2','3','4','5','6','7','8','9') then
> parsechar := parsechar || current_digit;
> end loop;
> return to_number(parsechar);
> END char2num;

You can get informative error messages by issuing the command "show errors".

I found 2:

  1. the lack of an 'end if' on the line before the 'end loop' and
  2. no length given on the declaration of parsechar.

You also don't seem to make any allowance for an invalid number coming in but that's not a compile issue.

Jim Lyons Received on Thu Jul 05 2001 - 09:59:45 CDT

Original text of this message

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