Oracle-确定行数并打印行数
我试图确定select语句返回的行是否超过1行。如果这是假的,我不想要任何结果。我试过以下方法Oracle-确定行数并打印行数,oracle,plsql,Oracle,Plsql,我试图确定select语句返回的行是否超过1行。如果这是假的,我不想要任何结果。我试过以下方法 select s.id_numeric,s.client_id,s.depth,s.fas_sample_type,s.profile_number from sample s where s.client_id = upper ('128336A') and s.id_numeric between 12325 and 12327 and s.fas_sample_type = sample_p
select s.id_numeric,s.client_id,s.depth,s.fas_sample_type,s.profile_number
from sample s
where s.client_id = upper ('128336A')
and s.id_numeric between 12325 and 12327
and s.fas_sample_type = sample_pkg.get_soil_sample
and s.status = sample_pkg.get_authorised_sample
and s.flg_released = constant_pkg.get_true
and rownum >= 1
上面的查询只起作用,因为我添加了rownum>=1。但一旦我添加rownum>1,就没有结果了。这应该会有帮助:
with base_data as (
select s.id_numeric,
s.client_id,
s.depth,
s.fas_sample_type,
s.profile_number
from sample s
where s.client_id = upper ('128336A')
and s.id_numeric between 12325 and 12327
and s.fas_sample_type = sample_pkg.get_soil_sample
and s.status = sample_pkg.get_authorised_sample
and s.flg_released = constant_pkg.get_true
)
select *
from base_data b
where (select count(*) from base_data) > 1
尝试使用
分析功能
,如下所示:
Select * from
(select s.id_numeric,
s.client_id,
s.depth,
s.fas_sample_type,
s.profile_number,
Count(1) over() as cnt
from sample s
where s.client_id = upper ('128336A')
and s.id_numeric between 12325 and 12327
and s.fas_sample_type = sample_pkg.get_soil_sample
and s.status = sample_pkg.get_authorised_sample
and s.flg_released = constant_pkg.get_true)
Where cnt > 1
干杯 当我在12325和12327之间更改s.id_numeric以使用另一个字段时,上述查询返回结果?您能解释一下这个查询吗?
Count(1)over()
返回查询返回的记录数。因此,当您删除和
条件时,必须获得多条记录<代码>分析功能是最适合您需求的方法。尝试在不使用的情况下执行新查询,其中cnt>1
,您将能够理解。当我更改时,上面的查询返回结果,s.id\u numeric介于12325和12327之间,以利用另一个字段?你能解释一下这个问题吗?对不起,我不明白这个问题。它按照您的要求执行-如果有超过1行,则返回数据。我使用了densite_rank函数根据上面的id_numeric标记每行。每个id\u数值参数有12个标准结果。标签更改后如何验证?