Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a problem with NVL function.I can use my in clause properyl but when i add nvl it gives error.

My query like this:

SELECT  ci.date, 
 SUM (cid.salary) amount, SUM (cid.slary_gross) gross_amount
    FROM students ci,
         orders cid           
 WHERE 
 ci.id IN  NVL((select id from sysadm.students
 where status = 'IN' AND student_id= 24514 ORDER BY id
 FETCH FIRST 3 ROWS ONLY), ci.id ) 

My error: 01427. 00000 - "single-row subquery returns more than one row"

?f I delete nvl function and just write like below it is running.How can i use nvl with in clause?

ci.id IN (select id from sysadm.students where status = 'IN' AND student_id= 24514 ORDER BY id FETCH FIRST 3 ROWS ONLY)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
177 views
Welcome To Ask or Share your Answers For Others

1 Answer

I doubt the id is NULL in the subquery. SO I would suggest:

with s3 as (
       select s.id
       from sysadm.students s.
       where s.status = 'IN' and s.student_id = 24514
       ORDER BY id
       FETCH FIRST 3 ROWS ONLY
      )
select . . .
where ci.id in (select id from s3) or
      not exists (select 1 from s3);

This checks if your id is in the list -- or that the list is empty.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...