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: numeric check

Re: numeric check

From: Ubiquitous <weberm_at_polaris.net>
Date: Thu, 24 Aug 2006 17:44:23 -0500
Message-ID: <pYKdncre3ORatnPZnZ2dnUVZ_rWdnZ2d@comcast.com>


In article <444d20e7$1_at_news.victoria.tc.ca>, yf110_at_vtn1.victoria.tc.ca wrote:
>Ubiquitous (weberm_at_polaris.net) wrote:
>: chrisval_at_gmail.com wrote:
>: >Malcolm Dew-Jones wrote:

>: >> -- untested
>: >> function is_a_number( s varchar2)
>: >> return number
>: >> is
>: >> begin
>: >> return to_number(s);
>: >> exception
>: >> -- This should check just the expected error
>: >> -- but I haven't bothered to look it up.
>: >> when others then
>: >> return NULL;
>: > end is_a_number;
>: >
>: >What you're looking for is: "INVALID_NUMBER"
>
>: I thinkthis throws a VALUE_ERROR exception. What's the difference?
>
>: Not to be pedantic, but shouldn't this function return a BOOLEAN
>: instead of a NUMBER, so you have something like:
>:
>: FUNCTION is_numeric(s VARCHAR2)
>: RETURN BOOLEAN
>: IS
>: return_value BOOLEAN := FALSE ;
>: v_numeric NUMBER := 0;
>: BEGIN
>: v_numeric := TO_NUMBER(s);
>: return_value := TRUE ;
>: RETURN return_value;
>: EXCEPTION
>: WHEN VALUE_ERROR THEN
>: RETURN return_value;
>: WHEN OTHERS THEN
>: DBMS_OUTPUT.put_line('Unexpected EXCEPTION!');
>: RETURN return_value;
>: END is_numeric;
>
>Yes, based on the name of the function, but I assume if you want the
>number then you want the number, so I return the number.

There's already a function out there for that: to_number This one tests a string.

-- 
It is simply breathtaking to watch the glee and abandon with which
the liberal media and the Angry Left have been attempting to turn
our military victory in Iraq into a second Vietnam quagmire. Too bad 
for them, it's failing.
Received on Thu Aug 24 2006 - 17:44:23 CDT

Original text of this message

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