oracle Where子句中的数字通配符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9419917/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 00:38:20  来源:igfitidea点击:

Number Wildcard in Where Clause

sqlregexdatabaseoracle

提问by jmq

I'm trying to add a number wildcard to a query to look for a number in a specific position. The query looks something like this:

我正在尝试向查询添加数字通配符以在特定位置查找数字。查询如下所示:

SELECT SUBMITTER
  FROM BASE_ELEMENT
 WHERE SUBMITTER LIKE 'm_%';

The problem with this query is that it picks up everything that starts with "m" and has a character in the second position. I need something that work like a Unix wildcard:

此查询的问题在于它选取以“m”开头且在第二个位置有一个字符的所有内容。我需要一些像 Unix 通配符一样工作的东西:

'm[0-9]*'

I want it to include m0, m1, m2, etc, but exclude ma, mb, mc, etc.

我希望它包括 m0、m1、m2 等,但不包括 ma、mb、mc 等。

How would I accomplish this in Oracle 10g?

我将如何在 Oracle 10g 中完成此操作?

回答by Ben

In 10G you have the wonderof regular expressions. So, your query could be:

在10G你有奇迹正则表达式。因此,您的查询可能是:

select submitter
  from base_element
 where regexp_like(submitter, '^m[[:digit:]]')

^anchors the expression to the start of the line and [[:digit:]]matches to any digit.

^将表达式锚定到行首并[[:digit:]]匹配任何数字。

回答by bruno.zambiazi

Try to use the REGEXP_LIKE function (http://docs.oracle.com/cd/B19306_01/appdev.102/b14251/adfns_regexp.htm).

尝试使用 REGEXP_LIKE 函数 (http://docs.oracle.com/cd/B19306_01/appdev.102/b14251/adfns_regexp.htm)。

Your case could be solved like this:

你的情况可以这样解决:

select submitter from base_element where regexp_like( submitter, '^m[0-9]' );

select submitter from base_element where regexp_like( submitter, '^m[0-9]' );

回答by Andomar

You could use regexp_like:

你可以使用regexp_like

where regexp_like(submitter, '^m\d')