Oracle,带有视图的ORDER BY导致错误

时间:2012-02-28 08:31:27

标签: oracle views sql-order-by ora-00979

我正在使用以下查询从视图中选择数据

SELECT * FROM "SCH"."MyView"

如果我添加ORDER BY

SELECT * FROM "SCH"."MyView"
ORDER BY Name

我收到以下错误

[Err] ORA-00979: not a GROUP BY expression

Oracle查询引擎是否将此转换为无效查询?如何开始对此类问题进行故障排除?

这是“SCH”的简化。“MyView”

SELECT
    Name,
    (subquery) AS Foo,
    (subquery) AS Bar
FROM
    "SCH"."AnotherView"
GROUP BY 
    Name

如果删除子查询,我可以使用ORDER BY而不会出现错误消息。子查询如下:

( SELECT f.UnitPrice FROM "SCH"."AnotherView" f WHERE f.Name = main.Name AND f.Category = 'x' AND rownum < 2 ) AS priceX
( SELECT b.UnitPrice FROM "SCH"."AnotherView" b WHERE b.Name = main.Name AND b.Category = 'y' AND rownum < 2 ) AS priceY

编辑:如果我添加“WHERE rownum&lt; 9999999”,我就摆脱了错误。我们正在运行版本10.2.0.4.0 64位。

1 个答案:

答案 0 :(得分:0)

也许您尝试执行包含SELECT函数的GROUP BY语句(即:MINMAXSUMCOUNT )和SELECT列表中不在GROUP BY子句中的表达式。