Ora 00900



Have you tried to run a query and got the “ORA-00979: not a group by expression” error? Learn what it is and how to resolve the error in this article.

Ora-00900: Invalid SQL Statement On EXECUTE IMMEDIATE Call PL/SQL object (Doc ID 2503264.1) Last updated on DECEMBER 19, 2019. Applies to: PL/SQL - Version 11.2.0.4 and later. ORA 00900: invalid SQL statement or ORA-06553. The database is Oracle 12c and only Toad for Oracle 12 or later supports Oracle 12c. Error: 'ORA-00900: invalid SQL statement' after executing procedure Oracle 10g Express Edition, Windows 7.

ORA-00979: not a group by expression

The ORA-00979 error happens when you have at least one column in your SELECT clause that is not in your GROUP BY expression when you are using an aggregate function. Common aggregate functions include SUM, AVG, MIN, MAX, and COUNT. Any column or expression in your SELECT clause must also be listed in the GROUP BY clause.

Here’s an example of a query that will generate the error:

Result:

Oracle Ora 00904 Invalid Identifier

ORA-00979: not a GROUP BY expression

Why Do I Get The ORA-00979 Error?

This error happens because you’re using an aggregate function, and there is at least one column in the SELECT clause that is not in the GROUP BY clause.

Using the example query above:

Because I use an aggregate function (COUNT), I need to define all of the columns in a GROUP BY clause that are in the SELECT clause.

In this example, I have specified the first_name and last_name column in the SELECT clause, but the last_name column is not in the GROUP BY clause.

Even if I have some fields in the GROUP BY clause, if I don’t specify all of the fields from the SELECT clause, I’ll still get an error.

For example:

Result:

ORA-00979: not a GROUP BY expression

As you can see, this will still give me an error.

Why does Oracle give an error?

Because, if you don’t have a GROUP BY but you want to SELECT the column, Oracle doesn’t know what value to show when using this aggregate function. Should it show the first value? The last value? A random value?

How To Resolve the ORA-00979 Error

To resolve the ORA-00979: not a group by expression error, simply ensure that all of the GROUP BY columns match the SELECT clause.

You can do this by adding columns to the GROUP BY.

Ora-00900 invalid sql statement c#

So, using the example above:

Result:

FIRST_NAMELAST_NAMECOUNT(*)
JohnSmith2
MarkAnderson1
MichaelCondor1
BrendanJefferson1
PeterStark1
SallyLincoln1
MichelleBrumby1
AmyFord1
RoseMinson1
TinaMitchell1

Or, using the second example:

Result:

FIRST_NAMELAST_NAMEADDRESS_STATECOUNT(*)
JohnSmithCalifornia1
MarkAndersonTexas1
MichaelCondorFlorida1
BrendanJeffersonFlorida1
PeterStarkIllinois1
SallyLincolnCalifornia1
MichelleBrumbyTexas1
AmyFordTexas1
RoseMinsonCalifornia1
TinaMitchellIllinois1
JohnSmithTexas1

The columns don’t need to be in the same order to correct the error. They just need to be present.

One thing to remember with a GROUP BY clause, is if you give your columns aliases, you need to specify the original column or expression.

Ora 00900 stored procedure

Ora 00900 Error

So, if you have a query like this:

00900

Result:

ORA-00904: “FULL_NAME”: invalid identifier

You get an error, because you can’t refer to a column alias within the GROUP BY clause. You’ll need to use a query like this:

FULL_NAMECOUNT(*)
John Smith2
Mark Anderson1
Michael Condor1
Brendan Jefferson1
Peter Stark1
Sally Lincoln1
Michelle Brumby1
Amy Ford1
Rose Minson1
Tina Mitchell1
Oracle

Conclusion

So, in conclusion, the ORA-00979: not a group by expression error happens because the columns in the SELECT clause don’t match the columns in the GROUP BY clause. To resolve the error, make sure the columns match.

Lastly, if you enjoy the information and career advice I’ve been providing, sign up to my newsletter below to stay up-to-date on my articles. You’ll also receive a fantastic bonus. Thanks!

Last updated on DECEMBER 19, 2019

Applies to:

PL/SQL - Version 11.2.0.4 and later
Generic (Platform Independent)

Symptoms

EXECUTE IMMEDIATE failed when calling PL/SQL object:

Changes

None

Cause

To view full details, sign in with your My Oracle Support account.

Don't have a My Oracle Support account? Click to get started!

Ora 00900 Stored Procedure

In this Document

Ora 20900


Symptoms
Changes
Cause
Solution
References


My Oracle Support provides customers with access to over a million knowledge articles and a vibrant support community of peers and Oracle experts.