Skip to content
Advertisement

SQLDeveloper runs query but getting a “ORA-00979: Not a Group By expression” from hibernate

I have data that looks something like this:

JavaScript

And a query that works fine in Oracle SQL Developer (It returns data averaged over 15 second periods):

JavaScript

but when I plug it into my java code, I get an error:

JavaScript

The actual query string I use in the Jave looks more like this:

JavaScript

and the parameters are set by calling:

JavaScript

Anyone know why I’m getting this “Not a GROUP BY expression” error?

I picked up this way of doing averaging over time intervals from Tom here: http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:4222062043865

EDIT It almost seemed to be resolved by the following:

JavaScript

Note: I used sampletime to rename the column, which is the name of one of the columns in the table. It wouldn’t work with the name “tspan” instead of sampletime:

JavaScript

When I named the new column sampletime, and used sampletime in the GROUP BY by clause, that error went away, and the query ran perfectly in SQLDeveloper. Unfortunately, when running from Java, it returned several identical rows for each sampletime. Grrrr….

SOLUTION: What did work is the chosen solution below — I took out the quotation marks and plus signs around the string to make it more readable here:

JavaScript

Advertisement

Answer

It looks like the JDBC driver is creating a unique bind variable name for each “?”. Unfortunately, in Oracle, the group by clauses must match character for character with the select clauses, and because of this, it doesn’t. I mocked up a table with your data in Oracle, and I ran a few test queries with dynamic SQL and bind variables. First, with sequentially named bind variables:

JavaScript

The results:

JavaScript

Second, with the same named bind variables:

JavaScript

The results:

JavaScript

So, try concatenating your averagingWindowInSeconds value to your query, instead of having those 4 bind variables.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement