Skip to Main Content

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question.

Asked: July 13, 2002 - 10:10 am UTC

Last updated: July 13, 2002 - 3:48 pm UTC

Version: 8.0.5.0.0

Viewed 1000+ times

You Asked

Hi Tom,

I have a varchar2 field and I want to change it number.
I want to check the all data in that field is all that data numbers (like IsNumber() function in C language).

Thanks,

and Tom said...

ops$tkyte@ORA817DEV.US.ORACLE.COM> create or replace function isNumber( p_string in varchar2 ) return number
2 as
3 x number;
4 not_a_number exception;
5 pragma exception_init( not_a_number, -6502 );
6 begin
7 x := to_number( p_string );
8 return 1;
9 exception
10 when not_a_number then
11 return 0;
12 end;
13 /

Function created.

ops$tkyte@ORA817DEV.US.ORACLE.COM>
ops$tkyte@ORA817DEV.US.ORACLE.COM> select 'a', isNumber( 'a' ) from dual
2 union all
3 select '1', isNumber( '1' ) from dual;

' ISNUMBER('A')
- -------------
a 0
1 1

ops$tkyte@ORA817DEV.US.ORACLE.COM>

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Thanks Tom

A reader, July 13, 2002 - 3:48 pm UTC

Thats what we was looking for.
Thanks

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library