带 in 子句的 nvl 函数

nvl function with in clause

我的 NVL 有问题 function.I 可以使用我的 in 子句 properyl 但是当我添加 nvl 时它会出错。

我的查询是这样的:

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 ) 

我的错误:01427. 00000 - "single-row subquery returns more than one row"

İf 我删除 nvl 函数并像下面这样写 running.How 我可以在子句中使用 nvl 吗?

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

我怀疑子查询中的 idNULL。所以我建议:

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);

这会检查您的 ID 是否在列表中,或者列表是否为空。