Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

udf question

Status
Not open for further replies.

AlexB1234

Programmer
Jul 9, 2003
26
US
Don't do much Oracle development, but I think I've got a simple problem.

I'm trying to test whether the value in a varchar field is numeric with the following user defined function. The problem is I don't know how to trap for an Oracle error inside the function.

Anyone?


CREATE OR REPLACE FUNCTION IsNumber
(
psString VARCHAR2
)
RETURN NUMBER
IS
n NUMBER;
BEGIN
/* Need to trap for error 06502 - conversion error and return 0 if it occurs*/
n := TO_NUMBER(psString);
RETURN -1;
END;
/
 
Try

Code:
CREATE OR REPLACE FUNCTION IsNumber (psString VARCHAR2)
RETURN NUMBER IS
  n  NUMBER;
BEGIN
  n := TO_NUMBER(psString);
  RETURN -1;
EXCEPTION
  WHEN OTHERS
  THEN
    Return 0;
END;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top