用于排除包含非数字字符的行的 Oracle SQL 查询
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10519898/
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
Oracle SQL query to exclude rows containing non-numeric characters
提问by Tom
I have the following oracle query which runs fine
我有以下运行良好的 oracle 查询
SELECT c.customercode, s.sales_id
FROM customers c
LEFT JOIN sales s ON c.customercode = s.sales_id
WHERE c.address IS NOT NULL
and it returns results looking something like this:
它返回看起来像这样的结果:
customercode sales_id
12345678 456
34534534 678
23423423 X123
What I would like to do is exclude rows where the sales_id contains anything other than numeric characters. So the above results would not include the 3rd row.
我想要做的是排除 sales_id 包含数字字符以外的任何内容的行。所以上面的结果不包括第三行。
回答by Justin Cave
You can use regular expressions. In this case, regexp_like( sales_id, '^[[:digit:]]*$' )
您可以使用正则表达式。在这种情况下,regexp_like( sales_id, '^[[:digit:]]*$' )
SQL> with x as (select 12345678 code, '456' sales_id from dual union all
2 select 34534534, '678' from dual union all
3 select 23423423, 'X123' from dual)
4 select *
5 from x
6 where regexp_like( sales_id, '^[[:digit:]]*$' );
CODE SALE
---------- ----
12345678 456
34534534 678