DECLARE
trn VARCHAR2(2) := 'DD';
cur SYS_REFCURSOR;
BEGIN
OPEN cur FOR
SELECT
TRUNC(some_date, trn),
NULL AS dummy_2,
COUNT( DISTINCT dummy_1 )
FROM
(SELECT SYSDATE AS some_date, ROWNUM AS dummy_1 FROM dual)
GROUP BY
TRUNC(some_date, trn);
END;
这适用于Oracle 10,但Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
导致:
ORA-00979:不是GROUP BY表达式
ORA-06512:第5行
有人可以复制/解释这个吗?谢谢!
答案 0 :(得分:6)
如果您有权访问支持,则看起来像Bug 9478304: LOOP FAILING WITH ORA-00979: NOT A GROUP BY EXPRESSION。这似乎仅影响11.2.0.1。
答案 1 :(得分:2)
我怀疑您的问题是NULL
中的SELECT
需要在GROUP BY
中,即使它是常数。我无法想象为什么它在Oracle 10中会起作用,但不会在11中起作用。
如果您删除NULL AS dummy_2
?
答案 2 :(得分:1)
这没有错误:
DECLARE
trn VARCHAR2(2) := 'DD';
cur SYS_REFCURSOR;
BEGIN
OPEN cur FOR
SELECT
TRUNC(some_date, dtrn),
NULL AS dummy_2,
COUNT( DISTINCT dummy_1 )
FROM
(SELECT SYSDATE AS some_date, ROWNUM AS dummy_1 FROM dual) data1,
(SELECT trn AS dtrn FROM dual) data2
GROUP BY TRUNC(some_date, dtrn);
END;
问题在于使用trn
函数中的TRUNC
变量和变量。也许是bug。
答案 3 :(得分:1)
截断内部选择中的sysdate似乎工作正常:
DECLARE
trn VARCHAR2(2) := 'DD';
cur SYS_REFCURSOR;
BEGIN
OPEN cur FOR
SELECT
some_date,
NULL AS dummy_2,
COUNT( DISTINCT dummy_1 )
FROM
(SELECT trunc(SYSDATE, trn) AS some_date, ROWNUM AS dummy_1 FROM dual)
GROUP BY
some_date;
END;