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: Malcolm Dew-Jones <yf110_at_vtn1.victoria.tc.ca>
Date: 27 Mar 2006 09:03:24 -0800
Message-ID: <44281adc$1@news.victoria.tc.ca>


Arto Viitanen (arto.viitanen_at_csc.fi) wrote:
: mr. ambastha wrote:
: > i just have a doubt. till date i was writing a pl sql function for
: > checking whether the entered number is numeric or not. can anyone tell
: > whether there is any built in function to check this? Earlier i was
: > using isdigit() and isnumeric() in other languages. is this kind of
: > functions available here?
: > thanks in advance,
: > regards,
: > -ambastha
: >

: Newer version (10g ??) of Oracle has regular expression functions.
: So you could use following in SQL*Plus:

: SQL> variable g_n varchar2(100)
: SQL> set serveroutput on
: SQL> begin
: :g_n := '1222';
: IF :g_n = regexp_substr(:g_n, '^[[:digit:]]+$') THEN
: dbms_output.put_line('OK');

Regular expressions, very powerful, everyone should own one, but they are also tricky, and easy to get wrong.

For example the above doesn't accomodate decimal points, and if it did it probably wouldn't accomodate the language settings for them, not to mention any other allowed representations of numbers. Not to say you shouldn't use RE's, often you should, just realize that they can be seductively simple but end up being a lot more work than you anticipated.

In this case I would go with to_number

$0.10 Received on Mon Mar 27 2006 - 11:03:24 CST

Original text of this message

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