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

Home -> Community -> Mailing Lists -> Oracle-L -> Re: package to check if the input chars are number

Re: package to check if the input chars are number

From: Jared Still <jkstill_at_bcbso.com>
Date: Fri, 7 Jul 2000 08:19:41 -0700 (PDT)
Message-Id: <10551.111438@fatcity.com>


On Thu, 6 Jul 2000, grace lim wrote:

> gurus,
>
> is there a package that can check if the input is a numeric or varchar when
> the variable has a varchar2 type?
>
> e.g. user input '123' === output is numeric
> '2rY' === output not numeric

There is a simple way to do this. It also happens to be the fastest method.

Give this a try:


create or replace function is_number( chk_data_in varchar2 ) return boolean
is

        dummy number(38,4);
begin

	dummy := to_number(chk_data_in);
	return true;

exception
when value_error then

        return false;
when others then

        raise;
end;
/         

show errors function is_number

declare

        v_test varchar2(10) := '12';
begin

	if is_number(v_test) then
		dbms_output.put_line(v_test || ' is a number');
	else
		dbms_output.put_line(v_test || ' is NOT a number');
	end if;

end;
/

Jared Still
Certified Oracle DBA and Part Time Perl Evangelist ;-) Regence BlueCross BlueShield of Oregon
jkstill_at_bcbso.com - Work - preferred address Received on Fri Jul 07 2000 - 10:19:41 CDT

Original text of this message

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