我想在oracle中从一个查询中返回多个值。对于ex:
select count(*)
from tablename a
where asofdate='10-nov-2009'
and a.FILENAME in (case
when 1 = 1 then (select distinct filename from tablename
where asofdate='10-nov-2009' and isin is null)
else null
end);我收到错误: ora 01427单行子查询返回多行
敬请指教。
谢谢,Deepak
发布于 2009-11-11 20:26:46
CASE语句不能返回多个值,它是一个处理一个值的函数。
这不是您的语句所必需的,此语句应该可以工作:
select count(*)
from tablename a
where asofdate='10-nov-2009'
and a.FILENAME in (select distinct filename
from tablename
where asofdate='10-nov-2009'
and isin is null);也许你脑海中有另一个使用场景?如下所示: Select * From aTable Where in CASE WHEN Then WHEN Then ELSE END
那么使用CASE可能不是正确的场景。也许这会帮助你走上正确的方向:
Select *
From aTable
Where <Case1> and column1 in <Subselect1>
Or <Case2> and column1 in <Subselect2>
OR Not (<Case1> Or <Case2>) and column1 in <Subselect3>但是对于优化器来说这可能是相当多的工作……
发布于 2009-11-11 20:27:15
Case语句中的distinct试图返回多个值,而您的SELECT语句当前只返回一行中的一个值。如果您正在尝试获取每个文件名的计数,请执行以下操作
SELECT FileName, Count(*)
FROM tablename
WHERE asofdate='10-nov-2009' and isin is null
GROUP BY FileName发布于 2009-11-11 20:24:43
运行以下查询:
select distinct filename from tablename
where asofdate='10-nov-2009' and isin is null您将看到它返回了多个行,这导致了ORA-01427。
https://stackoverflow.com/questions/1714823
复制相似问题