Q
Problem solve Get help with specific problems with your technologies, process and projects.

How can SQL test for pure numerics?

One of the mysteries I have never been able to solve is how to test a field for pure numerics in SQL.

One of the mysteries I have never been able to solve is how to test a field for pure numerics. We have instances where an attribute's contents determine the processing. Using COBOL I would write "if not NUMERIC". What is the SQL equivalent?

If it's a numeric datatype column, you don't have to test it at all. <grin>

So the question of how to test for pure numerics is relevant only to string datatype columns, like CHAR and VARCHAR. And the specific method is pretty much dictated by whatever functions may be available in your particular DBMS.

In DBMSs which have one, like SQL Server, use the ISNUMERIC() function. In MySQL and PostgreSQL, use a regular expression such as '^[0-9.]$'. Note that the decimal point should be considered one of the valid "numeric" characters.

This was last published in August 2007

Dig Deeper on Oracle and SQL

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchHRSoftware

Close