【发布时间】:2015-07-02 18:35:40
【问题描述】:
运行此查询(如下)返回“值过多”错误:
select
case
when to_char(sysdate, 'yyyymmdd') = to_char(sysdate, 'yyyymm') || '01'
then (select FirstReportGroups.*, FirstReportDetails.*
from FirstReportGroups, FirstReportDetails)
when to_char(sysdate, 'yyyymmdd') = to_char(sysdate, 'yyyymm') || '16'
then (select SecondReportGroups.*, SecondReportDetails.*
from SecondReportGroups, SecondReportDetails)
end as LetsSee
from cmtmpentered t1 join cmtmpconf t2
on t1.casenumber = t2.casenumber
and t1.enc = t2.enc
;
我正在使用 CTE(它们不包括在内,因为它会使这很长),这对我来说合乎逻辑,但是谷歌搜索这个“太多值”错误并没有给我任何实质性帮助。单独运行 CTE 可以正常工作,所以这不是问题。
我认为,如果我只能摆脱外部的“选择”语句并将选择保留在案例中,那么一切都会解决。如果我解释得不好,我正在寻找的一个例子是:
case
when to_char(sysdate, 'yyyymmdd') = to_char(sysdate, 'yyyymm') || '01'
then (select FirstReportGroups.*, FirstReportDetails.*
from FirstReportGroups, FirstReportDetails)
when to_char(sysdate, 'yyyymmdd') = to_char(sysdate, 'yyyymm') || '16'
then (select SecondReportGroups.*, SecondReportDetails.*
from SecondReportGroups, SecondReportDetails)
end as LetsSee
;
这在任何情况下都可行吗?这种语法显然不起作用,否则我不会问这个问题 - 但有没有相关的方法可以做到这一点?
【问题讨论】:
-
case在select语句中只返回一个值。您可以在 PL/SQL 代码中使用if。 -
您到底想要输出什么?似乎是 UNION 或 WITH 的情况,具体取决于您实际想要看到的内容。
标签: sql oracle oracle11g common-table-expression