ORACLE - Select Count on a Subquery(ORACLE - 选择子查询上的计数)
问题描述
我有一个包含一组范围(RangeA 和 RangeB)的 Oracle 表.这些列是 varchar,因为它们可以同时包含数字和字母数字值,如下例所示:
I've got an Oracle table that holds a set of ranges (RangeA and RangeB). These columns are varchar as they can hold both numeric and alphanumeric values, like the following example:
我需要执行一个只返回具有数值的记录的查询,并对该查询执行计数.到目前为止,我已经尝试使用两个不同的查询来执行此操作,但没有任何运气:
I need to to do a query that returns only the records that have numeric values, and perform a Count on that query. So far I've tried doing this with two different queries without any luck:
查询1:
查询 2:
子查询工作正常,因为我得到的两条记录只有数值,但查询的 COUNT 部分失败.我应该只得到 1,但我得到了以下错误:
The subquery is working fine as I'm getting the two records that have only numeric values, but the COUNT part of the query is failing. I should be getting only 1 on the count, but instead I'm getting the following error:
我做错了什么?非常感谢任何帮助.
What am I doing wrong? Any help is much appreciated.
推荐答案
可以用正则表达式测试每一列,判断是否为有效数字:
You can test each column with a regular expression to determine if it is a valid number:
另一种选择是使用用户定义的函数:
Another alternative is to use a user-defined function:
那么你可以这样做:
这篇关于ORACLE - 选择子查询上的计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!