Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wildcard Search for a numeric range

Tags:

I am trying to filter out a column (plan_name) which have internet plans of customers. Eg (200GB Fast Unlimited,Free Additional Mailbox,Unlimited VDSL...). I specifically want to filter out plans which do not have any numbers in them. The column is of type varchar2 and I'm querying an Oracle database. I have written the following code:

SELECT *
FROM   plans
WHERE  plan_name NOT LIKE '%[0-9]%'

However, this code still returns plans like 200GB fast that have numbers in them? Can anyone explain why this is?

like image 673
Starboi Avatar asked Jun 17 '20 21:06

Starboi


1 Answers

Oracle's like syntax does not support the kind of pattern matching you are trying. This is SQL Server syntax. Oracle interprets the pattern as a litteral '[0-9]' (which, obviously, something like '200GB'does not match).

However, unlike SQL Server, Oracle has proper suport for regular expression, through the regexp_* functions. If you want values that contain no digit, you can do:

where not regexp_like(plan_name, '\d')
like image 89
GMB Avatar answered Oct 11 '22 18:10

GMB