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.
Dig Deeper on Oracle and SQL
Related Q&A from Rudy Limeback
Read an example of an SQL case expression from our SQL expert Rudy Limeback. Continue Reading
Read SQL expert Rudy Limeback's advice for counting combinations in a table with SQL's GROUP BY clause Continue Reading
Read about the Mimer Validator, a tool used to verify your SQL code, in this tip from SQL expert Rudy Limeback. Continue Reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.