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!

Testing for Numeric Values inside a varchar2 field type 1

Status
Not open for further replies.

mozgheib

Programmer
Dec 14, 2003
50
KW
Hello,

I have a varchar2 field that has values
that are sometimes not numeric. However,
I am only interested in numeric values
since there are records that have numeric
values in that field.

SO I would like to test that field values
and only return the numeric values.

I was wondering what should my syntax look
like.

Thanks.
 
The most reliable way is to create a function.

Code:
CREATE FUNCTION isnum (p_char IN VARCHAR2)
RETURN NUMBER IS
  n1 NUMBER;
BEGIN
  n1 := To_Number(p_char);
  Return 0;
EXCEPTION
  WHEN OTHERS
  THEN
    Return 1;
END;

Then you can use it in SQL:

Code:
SELECT x
FROM   y
WHERE  isnum(z) = 0;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top