简体   繁体   English

通配符搜索数字范围

[英]Wildcard Search for a numeric range

I am trying to filter out a column (plan_name) which have internet plans of customers.我正在尝试过滤掉具有客户互联网计划的列(plan_name)。 Eg (200GB Fast Unlimited,Free Additional Mailbox,Unlimited VDSL...).例如(200GB 快速无限、免费附加邮箱、无限 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.该列的类型为 varchar2,我正在查询 Oracle 数据库。 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?但是,此代码仍会返回包含数字的 200GB 快速计划? Can anyone explain why this is?谁能解释这是为什么?

Oracle's like syntax does not support the kind of pattern matching you are trying. Oracle 的like语法不支持您尝试的那种模式匹配。 This is SQL Server syntax.这是 SQL 服务器语法。 Oracle interprets the pattern as a litteral '[0-9]' (which, obviously, something like '200GB' does not match). Oracle将该模式解释为文字'[0-9]' (显然, '200GB'类的内容不匹配)。

However, unlike SQL Server, Oracle has proper suport for regular expression, through the regexp_* functions.但是,与 SQL 服务器不同,Oracle 通过regexp_*函数对正则表达式有适当的支持。 If you want values that contain no digit, you can do:如果您想要不包含数字的值,您可以执行以下操作:

where not regexp_like(plan_name, '\d')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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