Oracle - определить количество строк и распечатать их - PullRequest
1 голос
/ 20 января 2020

Я пытаюсь определить погоду, более 1 строки возвращено из оператора select. Если это ложь, я не хочу никаких результатов. Я пробовал следующее.

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, результатов не будет.

Ответы [ 2 ]

1 голос
/ 20 января 2020

Попробуйте использовать analytical function следующим образом:

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

Ура !!

0 голосов
/ 20 января 2020

Это должно помочь:

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
...