简体   繁体   中英

Wildcard Search for a numeric range

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?

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM