7
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 行


任何人都可以重现/解释这一点吗?谢谢!

4

4 回答 4

6

如果您有权获得支持,它看起来像Bug 9478304: LOOP FAILING WITH ORA-00979: NOT A GROUP BY EXPRESSION。这似乎只影响 11.2.0.1。

于 2010-12-06T09:52:53.343 回答
2

我怀疑你的问题是即使它是一个常数NULL,你SELECT也需要在其中。GROUP BY不过,我无法想象为什么它会在 Oracle 10 而不是 11 中工作。

如果您删除它是否有效NULL AS dummy_2

于 2010-12-06T08:35:36.593 回答
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函数中使用。也许这是错误。

于 2010-12-06T09:25:38.007 回答
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;
于 2010-12-06T10:58:56.603 回答