Find Values That Don’t Contain Numbers in SQLite

The following example returns all rows that don’t contain any numbers in SQLite.

By “number” I mean “numerical digit”. Numbers can also be represented by words and other symbols, but for the purpose of this article, we’re returning values that don’t contain any numerical digits.

Sample Data

Suppose we have a table called Products with the following data in its ProductName column:

SELECT ProductName 
FROM Products;

Result:

ProductName                         
------------------------------------
Widget Holder (holds 5 gram widgets)
Widget Opener                       
Bob's "Best" Widget                 
Blue Widget                         
Urban Dictionary Version 1.2        
Beer Water (375ml)                  

Example Query

We can use the following query to return just those rows that don’t contain any numerical digits:

SELECT ProductName 
FROM Products
WHERE ProductName NOT REGEXP '[0-9]+';

Result:

ProductName        
-------------------
Widget Opener      
Bob's "Best" Widget
Blue Widget        

Only those rows that don’t contain any numerical digits are returned.

In SQLite, the REGEXP operator is a special syntax for the REGEXP() user function.

Therefore, we can use the following code to get the same result:

SELECT ProductName 
FROM Products
WHERE NOT REGEXP('[0-9]+', ProductName);

Result:

ProductName        
-------------------
Widget Opener      
Bob's "Best" Widget
Blue Widget