Home » RDBMS Server » Server Administration » Check to see if a field has a valid to_number ability
Check to see if a field has a valid to_number ability [message #371532] Thu, 02 November 2000 16:07 Go to next message
David Mancha
Messages: 1
Registered: November 2000
Junior Member
I need to check whether a number has a valid to_number capability and if so convert to a number, else null.

What text would create this?
Re: Check to see if a field has a ... try this [message #371539 is a reply to message #371532] Fri, 03 November 2000 11:47 Go to previous message
Andrew again...
Messages: 270
Registered: July 2000
Senior Member
CREATE OR REPLACE FUNCTION to_num (v_value IN VARCHAR2)
RETURN NUMBER
IS
v_retval NUMBER;
BEGIN
v_retval := TO_NUMBER (v_value);-- try to convert it!
RETURN v_retval;-- return the number!
EXCEPTION
WHEN OTHERS
THEN
RETURN NULL;-- Whoops! cant convert, return null!
END to_num;

select to_num('123') from dual;
select to_num(123) from dual;
select to_num('xyz') from dual;
Previous Topic: Re: Optimizer hints - help needed
Next Topic: Re: Executing an oracle stored procedure through ASP
Goto Forum:
  


Current Time: Thu May 02 07:06:21 CDT 2024