oracle ora-00979 symfony2 doctrine2

时间:2014-06-12 20:26:47

标签: sql oracle symfony doctrine-orm dql

我正在构建以下DQL:

SELECT partial operador.{id, pmn, neteo},                           
sum(outcollect.montoTotal) as montoOut,
outcollect.periodo as periodo,
outcollect.pagado
FROM RoamingOperadoresBundle:Operador operador
LEFT JOIN operador.operadorHub operadorHub 
LEFT JOIN operador.outcollect outcollect
WHERE operador.ishub = 0
AND operador.neteo = 1                          
AND operador.incluirReportes = 1
AND operador.pmn not in('CHLTM', 'CHLCM')
AND operador.id not in(SELECT op.id 
                       FROM RoamingOperadoresBundle:Operador op
                       LEFT JOIN op.operadorHub opHub
                       LEFT JOIN op.outcollect out
                       WHERE (opHub.desde <= out.periodo and (opHub.hasta >= out.periodo or opHub.hasta is null))
                       )
AND operador.activo = 1
GROUP BY operador.pmn, outcollect.periodo ORDER BY operador.pmn

哪个转换为这个SQL:

SELECT o0_.id AS ID0, 
o0_.pmn AS PMN1, 
o0_.neteo AS NETEO2, 
sum(o1_.monto_total) AS SCLR3, 
o1_.periodo AS PERIODO4, 
o1_.pagado AS PAGADO5 
FROM operador o0_ 
LEFT JOIN operador_hub o2_ ON o0_.id = o2_.operador_id 
LEFT JOIN outcollect o1_ ON o0_.id = o1_.operador_id 
WHERE o0_.ishub = 0 
AND o0_.neteo = 1 
AND o0_.incluirReportes = 1 
AND o0_.pmn NOT IN ('CHLTM', 'CHLCM') 
AND o0_.id NOT IN (SELECT o3_.id FROM operador o3_ LEFT JOIN operador_hub o4_ ON o3_.id = o4_.operador_id LEFT JOIN outcollect o5_ ON o3_.id = o5_.operador_id WHERE (o4_.desde <= o5_.periodo AND (o4_.hasta >= o5_.periodo OR o4_.hasta IS NULL))) 
AND o0_.activo = 1 
GROUP BY o0_.pmn, o1_.periodo 
ORDER BY o0_.pmn ASC

出现以下错误:

ORA-00979: no es una expresión GROUP BY

有关如何更改DQL以解决此问题的任何指示?

我使用的是doctrine2,symfony2和OCI8

1 个答案:

答案 0 :(得分:1)

每个Oracle文档

  

ORA-00979不是GROUP BY表达式       原因:GROUP BY子句不包含SELECT子句中的所有表达式。 SELECT未包含在组中的表达式   函数,如AVG,COUNT,MAX,MIN,SUM,STDDEV或VARIANCE,必须   列在GROUP BY子句中。

Action: Include in the GROUP BY clause all SELECT expressions that 
  are not group function arguments.

因此,您需要将select list中的所有表达式/列都包含在group by中。将SQL查询的group by更改为

group by o0_.pmn, o1_.periodo, o0_.neteo, o1_.pagado, o0_.id

GROUP BY DQL

GROUP BY operador.pmn, outcollect.periodo, operador.id, 
operador.neteo, outcollect.pagado