Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: package to check if the input chars are number
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;
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;
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