首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Oracle -确定行数并打印行数

Oracle -确定行数并打印行数
EN

Stack Overflow用户
提问于 2020-01-20 18:36:39
回答 2查看 50关注 0票数 1

我正在尝试确定select语句返回的行是否超过1行。如果这是假的,我不想要任何结果。我已经尝试了以下几种方法。

代码语言:javascript
复制
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,就没有结果了。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-01-20 18:52:28

这应该会有帮助:

代码语言:javascript
复制
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
票数 0
EN

Stack Overflow用户

发布于 2020-01-20 19:25:14

尝试使用analytical function,如下所示:

代码语言:javascript
复制
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

干杯!!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59821455

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档