简体   繁体   English

内联视图中的 ORA-1427

[英]ORA-1427 in inline view

We have a query that fails in our Prod environment that fails with ora-01427 single-row subquery returns more rows.我们的 Prod 环境中有一个查询失败,该查询因 ora-01427 单行子查询返回更多行而失败。 This is oracle 11g database.这是 oracle 11g 数据库。 Query as below.如下查询。 This query runs fine till we add the final left outer join with SQ3, once added it fails with ORA-1427 after some time.这个查询运行良好,直到我们用 SQ3 添加最后的左外连接,一旦添加它会在一段时间后失败并出现 ORA-1427。

select c1,c2..c8 from
t1 left join
(subquery with joins)SQ1
left join
(subquery with joins)SQ2
left join
(subquery with joins)SQ4
left join
(subquery with joins)SQ5
left join
(SELECT DISTINCT MAX(c1) c1, c2, c3, c4, c5,c6 
     FROM s1.t1 WHERE  c2='NY' AND c7<'2' AND c8='Y' 
GROUP BY c1, c2, c3, c4, c5,c6) SQ3 ON sq3.c3=t1.c3
                                                 AND sq3.c8=t1.c8
                                                  AND sq3.c7=t2.c6
                                                  AND sq3.c6 <'2'
                                                AND sq3.c4='Y' 

When i rewrite this query using WITH clause then it runs fine, see below.当我使用 WITH 子句重写此查询时,它运行良好,见下文。 Any idea on why the first query fails when the second one below executes with no change to logic.当下面的第二个执行没有改变逻辑时,为什么第一个查询失败的任何想法。

with
(SELECT DISTINCT MAX(c1) c1, c2, c3, c4, c5,c6 
     FROM s1.t1 WHERE  c2='NY' AND c7<'2' AND c8='Y' 
GROUP BY c1, c2, c3, c4, c5,c6) as SQ3
select c1,c2..c8 from
t1 left join
(subquery with joins)SQ1
left join
(subquery with joins)SQ2
left join
(subquery with joins)SQ4
left join
(subquery with joins)SQ5
left join
 SQ3 ON sq3.c3=t1.c3
 AND sq3.c8=t1.c8
 AND sq3.c7=t2.c6
 AND sq3.c6 <'2'
 AND sq3.c4='Y' 

Mira a ver esto de agrupar por la columna del agregado, no parece correcto (SELECT DISTINCT MAX(c1) c1 , c2, c3, c4, c5,c6 FROM s1.t1 WHERE c2='NY' AND c7<'2' AND c8='Y' ** Mira a ver esto de agrupar por la columna del agregado, no parece correcto (SELECT DISTINCT MAX(c1) c1 , c2, c3, c4, c5,c6 FROM s1.t1 WHERE c2='NY' AND c7<'2' AND c8='Y' **

GROUP BY c1c1 分组

** **

You don't need to group by the column you are using with your aggregate function.您不需要按与聚合 function 一起使用的列进行分组。 So change your last query to -因此,将您的最后一个查询更改为 -

SELECT MAX(c1) c1, c2, c3, c4, c5,c6 
  FROM s1.t1
 WHERE c2 = 'NY'
   AND c7 < '2'
   AND c8 = 'Y' 
 GROUP BY c2, c3, c4, c5,c6

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM