
Learn the cause and how to resolve the ORA-00934 error message in Oracle.
Description
When you encounter an ORA-00934 error, the following error message will appear:
- ORA-00934: group function is not allowed here
Resolution
The option(s) to resolve this Oracle error are:
Option #1
Try removing the group function from the WHERE clause or GROUP BY clause. If required, you can move the group function to the HAVING clause.
For example, if you tried to execute the following SQL statement:
SELECT department, SUM(sales) AS "Total sales" FROM order_details WHERE SUM(sales) > 1000 GROUP BY department;
You would receive the following error message:

You could correct this statement by using the HAVING clause as follows:
SELECT department, SUM(sales) AS "Total sales" FROM order_details GROUP BY department HAVING SUM(sales) > 1000;
Option #2
You could also try moving the group by function to a SQL subquery.
For example, if you tried to execute the following SQL statement:
SELECT department, SUM(sales) AS "Total sales" FROM order_details WHERE SUM(sales) > 1000 GROUP BY department;
You would receive the following error message:

You could correct this statement by using a subquery as follows:
SELECT order_details.department,
SUM(order_details.sales) AS "Total sales"
FROM order_details, (SELECT department, SUM(sales) AS "Sales_compare"
FROM order_details
GROUP BY department) subquery1
WHERE order_details.department = subquery1.department
AND subquery1.Sales_compare > 1000
GROUP BY order_details.department;
May 27, 2021
I got ” ORA-00934: group function is not allowed here ” error in Oracle database.
ORA-00934: group function is not allowed here
Details of error are as follows.
SELECT name, surname count(*) FROM employee WHERE Count(*) > 1 GROUP BY surname; ORA – 00934: GROUP FUNCTION IS NOT ALLOWED HERE 00964, 00000 – “group function is not allowed here”
GROUP FUNCTION IS NOT ALLOWED HERE
This ORA-00934 error is related to the group function which is not allowed.
You need to use HAVING CLAUSE For filtering if you use Aggregate function ( AVG, COUNT, MAX, MIN, SUM, STDDEV, or VARIANCE, ) in where clause.
To solve this error, use HAVING clause instead of where like following.
SELECT name, surname count(*) FROM employee GROUP BY surname HAVING Count(*) > 1;
Do you want to learn Oracle Database for Beginners, then read the following articles.
Oracle Tutorial | Oracle Database Tutorials for Beginners ( Junior Oracle DBA )
1,446 views last month, 1 views today
About Mehmet Salih Deveci
![]()
I am Founder of SysDBASoft IT and IT Tutorial and Certified Expert about Oracle & SQL Server database, Goldengate, Exadata Machine, Oracle Database Appliance administrator with 10+years experience.I have OCA, OCP, OCE RAC Expert Certificates I have worked 100+ Banking, Insurance, Finance, Telco and etc. clients as a Consultant, Insource or Outsource.I have done 200+ Operations in this clients such as Exadata Installation & PoC & Migration & Upgrade, Oracle & SQL Server Database Upgrade, Oracle RAC Installation, SQL Server AlwaysOn Installation, Database Migration, Disaster Recovery, Backup Restore, Performance Tuning, Periodic Healthchecks.I have done 2000+ Table replication with Goldengate or SQL Server Replication tool for DWH Databases in many clients.If you need Oracle DBA, SQL Server DBA, APPS DBA, Exadata, Goldengate, EBS Consultancy and Training you can send my email adress [email protected].- -Oracle DBA, SQL Server DBA, APPS DBA, Exadata, Goldengate, EBS ve linux Danışmanlık ve Eğitim için [email protected] a mail atabilirsiniz.
|
Vyzov 6 / 6 / 2 Регистрация: 19.02.2013 Сообщений: 68 |
||||||||
|
1 |
||||||||
Подзапрос27.05.2014, 17:07. Показов 3188. Ответов 8 Метки нет (Все метки)
Есть запрос:
Он выдает такую штуку ID COUNT(РАБОТА.РАБОТАID) MAX(РАБОТА.ЦЕНА) Теперь нужно из этого вложенного запроса вытащить ID врача (тобишь четверочку), который сделал больше всего самой дорогой работы. У меня это выглядит вот так…
Но такая вот беда: ORA-00934: group function is not allowed here
__________________
0 |
|
Programming Эксперт 94731 / 64177 / 26122 Регистрация: 12.04.2006 Сообщений: 116,782 |
27.05.2014, 17:07 |
|
Ответы с готовыми решениями:
SELECT Подзапрос в триггере Исправить подзапрос Подзапрос из другой БД 8 |
|
alexey1327 |
||||
|
27.05.2014, 22:54 |
2 |
|||
|
Можно просто отсортировать ваш запрос по MAX(РАБОТА.ЦЕНА) desc и выбрать rownum = 1
|
|
25 / 25 / 10 Регистрация: 20.09.2009 Сообщений: 110 |
|
|
28.05.2014, 08:36 |
3 |
|
alexey1327, А Вас не смущает тот факт, что на поиски одной строки вы тратите большое количество ресурсов на группировку и явную сортировку? ИМХО, ваш код, как минимум, слишком ресурсозатратен… Добавлено через 14 минут Добавлено через 2 минуты
0 |
|
Vyzov 6 / 6 / 2 Регистрация: 19.02.2013 Сообщений: 68 |
||||
|
29.05.2014, 22:08 [ТС] |
4 |
|||
|
Как оказалось, данное решение проблемы не подходит, нужно именно через вложенные запросы…
Это все что я осилил, выдает максимальное количество самой дорогостоящей работы, правда дальше у меня все упирается в конфликт логик построения вложенных запросов =( Добавлено через 2 часа 56 минут
0 |
|
25 / 25 / 10 Регистрация: 20.09.2009 Сообщений: 110 |
|
|
30.05.2014, 07:48 |
5 |
|
в сообщении, выше твоего, я написал уже, что тебе следует использовать dense_rank
0 |
|
Vyzov 6 / 6 / 2 Регистрация: 19.02.2013 Сообщений: 68 |
||||||||
|
02.06.2014, 14:28 [ТС] |
6 |
|||||||
|
Сваял я запрос с подзапросами выдающий то, что требуется:
Препод сказал что сие есть слишком хитро (для кого я так и не понял)
вместо перечисления таблиц ВИЗИТ, РАБОТА, ВРАЧ ломает запрос =( Визит
0 |
|
25 / 25 / 10 Регистрация: 20.09.2009 Сообщений: 110 |
|
|
02.06.2014, 15:37 |
7 |
|
честно говоря, я 5 раз прочитал. но так и не понял в чем у тебя загвоздка. Зачем ты изобретаешь велосипед, мне также непонятно. Открой для себя аналитические функции. DENSE_RANK
0 |
|
6 / 6 / 2 Регистрация: 19.02.2013 Сообщений: 68 |
|
|
03.06.2014, 09:08 [ТС] |
8 |
|
честно говоря, я 5 раз прочитал. но так и не понял в чем у тебя загвоздка. Загвоздка в том, что я сделал то что от меня просили. Теперь же требуют точно того же, но со связями таблиц (Inner join)… хотя у меня это заменено условиями подзапроcов в разделе where… Препод категорически отказывается это понимать и требует inner join’ов… т.к. я это решение еле придумал, других вариантов я не вижу, а они нужны =(
0 |
|
mlc 25 / 25 / 10 Регистрация: 20.09.2009 Сообщений: 110 |
||||
|
03.06.2014, 10:23 |
9 |
|||
|
Vyzov, я так понял в доку вы смотреть на dense_rank не хотите. Вот тогда наглядный пример
0 |
Подзапрос с группировкой