Home » SQL & PL/SQL » SQL & PL/SQL » "ORA-00979: not a GROUP BY expression" at runtime? (Oracle 10.2.0.4, AIX)
"ORA-00979: not a GROUP BY expression" at runtime? [message #478916] Wed, 13 October 2010 10:13 Go to next message
ThomasG
Messages: 3212
Registered: April 2005
Location: Heilbronn, Germany
Senior Member
Hello,

I ran into something that has me wondering about which errors are caught at compile-time, and which are caught at runtime. There is a pretty big package with lots of complicated queries that heavily use GROUP BY, and in the last couple of years I thought I never had the case of an ORA-00979 happening an RUNTIME, which is now happening.

The last heavy changes in that package did I make in the Oracle 9.2 days, and I *believe* (although my memory might be wrong) that back then the ORA-00979 errors came up at compile time.

So is it normal that the error doesn't show up during compile time, only during runtime, or should it be considered a bug?

SQL> CREATE TABLE test_tab(a NUMBER(1), b NUMBER(1));

Table created.

SQL> INSERT INTO test_tab VALUES (1,1);

1 row created.

SQL>
SQL> CREATE OR REPLACE PROCEDURE test_prod AS
  2    v_a NUMBER;
  3    v_b NUMBER;
  4  BEGIN
  5
  6  SELECT a,b
  7    INTO v_a, v_b
  8    FROM test_tab
  9   GROUP BY a;
 10
 11  END;
 12  /

Procedure created.

SQL>
SQL> BEGIN
  2  test_prod;
  3  END;
  4  /
BEGIN
*
ERROR at line 1:
ORA-00979: not a GROUP BY expression
ORA-06512: at "PFK.TEST_PROD", line 6
ORA-06512: at line 2

[Updated on: Wed, 13 October 2010 10:25]

Report message to a moderator

Re: "ORA-00979: not a GROUP BY expression" at runtime? [message #478922 is a reply to message #478916] Wed, 13 October 2010 11:31 Go to previous messageGo to next message
Michel Cadot
Messages: 68757
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
I get the same behaviour in 9.2.0.8 and 11.2.0.1.

I think SQL syntax analyzer in PL/SQL engine does not check the whole syntax because it does not check the scope of the "variables"; here are 3 examples that refer to a PL/SQL variable and so is valid:
SQL> CREATE OR REPLACE PROCEDURE test_prod AS
  2    v_a NUMBER;
  3    v_b NUMBER;
  4    b number;
  5  BEGIN
  6    SELECT a,test_prod.b
  7    INTO v_a, v_b
  8    FROM test_tab
  9    GROUP BY a;
 10  END;
 11  /

Procedure created.

SQL> exec test_prod;

PL/SQL procedure successfully completed.

SQL> CREATE OR REPLACE PROCEDURE test_prod AS
  2    v_a NUMBER;
  3    v_b NUMBER;
  4    c number;
  5  BEGIN
  6    SELECT a,c
  7    INTO v_a, v_b
  8    FROM test_tab
  9    GROUP BY a;
 10  END;
 11  /

Procedure created.

SQL> exec test_prod;

PL/SQL procedure successfully completed.

SQL> CREATE OR REPLACE PROCEDURE test_prod AS
  2    v_a NUMBER;
  3    v_b NUMBER;
  4    b number;
  5  BEGIN
  6    SELECT a,b
  7    INTO v_a, v_b
  8    FROM (select a, b c from test_tab)
  9    GROUP BY a;
 10  END;
 11  /

Procedure created.

SQL> exec test_prod;

PL/SQL procedure successfully completed.

It is just an assumption, I think the best should be to open a SR there is surely a good reason.

Regards
Michel

[Updated on: Wed, 13 October 2010 11:32]

Report message to a moderator

Re: "ORA-00979: not a GROUP BY expression" at runtime? [message #478923 is a reply to message #478922] Wed, 13 October 2010 11:48 Go to previous messageGo to next message
ramoradba
Messages: 2457
Registered: January 2009
Location: AndhraPradesh,Hyderabad,I...
Senior Member
Good one .
here is My result...
SQL> CREATE OR REPLACE PROCEDURE test_prod AS
  2        v_a NUMBER;
  3        v_b NUMBER;
  4      BEGIN
  5      SELECT a,b
  6        INTO v_a, v_b
  7        FROM test_tab
  8       GROUP BY a;
  9     END;
 10  /

Procedure created.

SQL> CREATE OR REPLACE PROCEDURE test_prod AS
  2        v_a NUMBER;
  3        v_b NUMBER;
  4      BEGIN
  5       SELECT  k,s
  6         INTO v_a, v_b
  7   FROM test_tab
  8  GROUP BY a;
  9      END;
 10   /

Warning: Procedure created with compilation errors.

SQL> sho err
Errors for PROCEDURE TEST_PROD:

LINE/COL ERROR
-------- -----------------------------------------------------------------
5/6      PL/SQL: SQL Statement ignored
5/16     PL/SQL: ORA-00904: "S": invalid identifier
SQL> 
SQL> desc test_tab
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 A                                                  NUMBER(1)
 B                                                  NUMBER(1)

SQL> select banner from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE    10.2.0.1.0      Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production


SQL>  CREATE OR REPLACE PROCEDURE test_prod AS
  2         v_a NUMBER;
  3         v_b NUMBER;
  4       BEGIN
  5        SELECT  a,test_tab.b
  6          INTO v_a, v_b
  7    FROM test_tab
  8   GROUP BY a;
  9       END;
 10   /

Procedure created.

SQL> exec test_prod;
BEGIN test_prod; END;

*
ERROR at line 1:
ORA-00979: not a GROUP BY expression
ORA-06512: at "SCOTT.TEST_PROD", line 5
ORA-06512: at line 1


so IMO might be it wont check with syntax errors for "group by" clause at compile time ?

sriram
Re: "ORA-00979: not a GROUP BY expression" at runtime? [message #478934 is a reply to message #478923] Wed, 13 October 2010 13:02 Go to previous messageGo to next message
ThomasG
Messages: 3212
Registered: April 2005
Location: Heilbronn, Germany
Senior Member
Thanks for the test, Michel, Ramoradba.

So it seems while my memory is flakier than I thought my pre-release testing has been better than I thought. Laughing

Re: "ORA-00979: not a GROUP BY expression" at runtime? [message #479248 is a reply to message #478934] Fri, 15 October 2010 09:23 Go to previous messageGo to next message
ramoradba
Messages: 2457
Registered: January 2009
Location: AndhraPradesh,Hyderabad,I...
Senior Member
reply from TOM

Quote:
it is simply this:

there are compile time errors and there are runtime errors, just as there are in *every* programming language ever invented.

this compiles to:

begin
dbms_output.put_line( 'answer = ' || 1/0 );
end;


but it isn't going to run. The first SQL you provided is syntactically 'correct', it isn't until they go to run it (which they do not do during compilation, they parse it - but they do not RUN it) that they discover "it isn't going to work"


The second sql cannot be parsed - the parsing cannot resolve what sriram is in the context it was used. Hence, the sql is not parseable and that is known at compile time.


sriram
Re: "ORA-00979: not a GROUP BY expression" at runtime? [message #479254 is a reply to message #479248] Fri, 15 October 2010 10:08 Go to previous message
Michel Cadot
Messages: 68757
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Tom prefers that we put a link to his answers rather than (or in addition to) quote him.
Here it is:
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:2691282300346240743#2696061500346537491

Regards
Michel
Previous Topic: pseudo columns (2 merged)
Next Topic: use of '&'
Goto Forum:
  


Current Time: Sun Apr 27 01:13:01 CDT 2025