"ORA-00979: not a GROUP BY expression" at runtime? [message #478916] |
Wed, 13 October 2010 10:13  |
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   |
 |
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   |
 |
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
|
|
|
|
|
|