`

Oracle常见错误

阅读更多
ORA-00979: not a GROUP BY expression

当用到组函数时,出现在select列表中的字段,如果没有在组函数中,那么必须出现在group by子句中!
Cause:The GROUP BY clause does not contain all the expressions in the SELECT clause. SELECT expressions that are not included in a group function, such as AVG, COUNT, MAX, MIN, SUM, STDDEV, or VARIANCE, must be listed in the GROUP BY clause.
Action:Include in the GROUP BY clause all SELECT expressions that are not group function arguments.


ORA-00937: not a single-group group function

如果在select列表项中除了包含聚合函数外,还包含了表的某些列,那么你将必须使用group by语句。
Cause:A SELECT list cannot include both a group function, such as AVG, COUNT, MAX, MIN, SUM, STDDEV, or VARIANCE, and an individual column expression, unless the individual column expression is included in a GROUP BY clause.
Action:Drop either the group function or the individual column expression from the SELECT list or add a GROUP BY clause that includes all individual column expressions listed.


在where子句和group by子句中不允许使用聚合函数,否则会报:
ORA-00934: group function is not allowed here

Cause:One of the group functions, such as AVG, COUNT, MAX, MIN, SUM, STDDEV, or VARIANCE, was used in a WHERE or GROUP BY clause.
Action:Remove the group function from the WHERE or GROUP BY clause. The desired result may be achieved by including the function in a subquery or HAVING clause.
http://techonthenet.com/oracle/errors/ora00934.php
引用
Cause:You tried to execute an SQL statement that included one of the group functions (ie: MIN, MAX, SUM, COUNT) in either the WHERE clause or the GROUP BY clause.
Action:The options to resolve this Oracle error are:
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 will receive the error "ORA-00934: group function is not allowed here"
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;

2 You could also try moving the group by function to a 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 will receive the error "ORA-00934: group function is not allowed here"
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;

本博客相关解释:http://wuaner.iteye.com/blog/513099
引用
Illegal  Queries Using Group Functions:
- You cannot use the WHERE clause to restrict groups.  (即where子句中不允许使用聚合函数)
- You use the HAVING clause to restrict groups.(可以使用having子句为聚合函数加限定条件)
- You cannot use group functions in the WHERE clause.(即where子句中不允许使用聚合函数)





group by和order by的列可以不在select中;
用到了聚合函数并同时使用group by和order by时,select和order by中不在聚合函数里的columns必须都出现在group by中!
如,下面的写法会报“not a GROUP BY expression”:
select deptno, sum(sal) 
from emp 
group by deptno
order by deptno,job

正确的写法是:
select deptno, sum(sal) 
from emp 
group by deptno,job
order by deptno,job

分享到:
评论

相关推荐

    Oracle常见错误代码

    Oracle常见错误代码 Oracle常见错误代码  以下表格中收集了Oracle中常见错误代码。

    浅谈Oracle常见错误处理

    下面将对Oracle常见错误的处理方法进行详细探讨。 首先,关于数据库恢复,在文档中特别提到“数据库非常规恢复”的注意事项。文档明确指出,以下内容仅供在非生产环境测试使用,而不能用于生产环境数据库。这强调了...

    oracle常见错误分析一览表

    本篇文章将详细解析部分Oracle常见错误及其原因,帮助你更好地理解和解决这些问题。 1. ORA-00001: 违反唯一约束条件 这个错误表示尝试插入或更新的数据违反了表中的唯一键约束。这意味着有重复的值试图插入到定义...

    oracle常见错误精集

    ### Oracle常见错误精集知识点详解 #### 一、Oracle 基础问题及解决方法 ##### 1. ORA-12541: TNS: 没有监听器 **原因**: 当遇到ORA-12541错误时,通常是因为监听器未启动或者监听器存在问题。 **解决方案**: - ...

    Oracle常见错误及解决方法Oracle常见错误及解决方法

    Oracle常见错误及解决方法Oracle常见错误及解决方法

    oracle常见错误代码的分析与解决

    本文将详细介绍 Oracle 常见错误代码的分析与解决方法,旨在帮助读者快速解决 Oracle 错误问题,提高数据库管理效率。 错误代码 ORA-01650 ORA-01650 错误代码是 Oracle 数据库管理员最常见的错误信息之一,产生...

    Oracle常见错误处理

    ### Oracle常见错误处理 #### 一、物理与逻辑块损坏 在Oracle数据库中,数据存储在物理块中,这些块可能会出现物理或逻辑损坏。理解这些错误及其处理方法对于维护数据库稳定性和数据完整性至关重要。 ##### 物理...

    ORACLE常见错误代码的分析与解决

    ### ORACLE常见错误代码的分析与解决 在Oracle数据库管理过程中,遇到各种错误代码是不可避免的。本文将针对几个常见的Oracle错误代码进行深入解析,并提供相应的解决方案,帮助数据库管理员及开发人员更好地理解和...

    oracle常见错误集(01653\12541\12537)和处理方法

    "Oracle 常见错误集(01653、12541、12537)和处理方法" Oracle 是一种广泛使用的关系型数据库管理系统,但是在实际使用中,我们经常会遇到各种错误,影响数据库的正常运行。本文将介绍三个常见的 Oracle 错误:Ora...

    如何解决Oracle 常见错误 ORA-04031(PDF)

    ### 如何解决Oracle常见错误 ORA-04031 #### 一、与共享池相关的实例参数 在深入探讨如何解决ORA-04031错误之前,我们需要先了解几个与共享池(`shared pool`)密切相关的Oracle实例参数: 1. **`SHARED_POOL_SIZE`...

    Oracle常见错误代码的分析与解决.rar_oracle

    Oracle常见错误代码的分析与解决,从这里可以看到那些常见的错误并有解决方案

    Oracle常见错误代码的分析与解决

    Oracle常见错误代码的分析与解决 Oracle错误代码的分析与解决

    oracle常见错误号

    以下是一些常见的Oracle错误号及其原因和解决办法: 1. ORA-01002:fetch out of sequence - 当游标没有正确地按照执行顺序进行操作时,比如在未调用`OPEN`、`FETCH`或`CLOSE`之前尝试`FETCH`,会出现这个错误。...

    Oracle常见错误总结

    本文将总结一些常见的Oracle错误及其解决方案。 首先,我们来看第一个错误:ORA-28056。这个错误通常发生在审计功能尝试将记录写入Windows事件日志时失败。错误信息“OSD-160222236: Message 160222236 not found; ...

    oracle常见错误及解决方法

    以下是一些常见的Oracle错误及其解释和解决方法: 1. ORA-00001: 违反唯一约束条件 当尝试插入或更新的数据在具有唯一约束(如唯一索引)的列中存在重复值时,会出现此错误。解决方法是检查插入或更新的数据,确保...

    oracle常见错误解析

    本篇文章将详细解析一些Oracle数据库中常见的错误,帮助你更好地理解和解决这些问题,从而更熟练地操作Oracle。 1. ORA-00922: 无法识别的选项 这个错误通常发生在创建或修改表时,可能是因为指定了Oracle不支持的...

Global site tag (gtag.js) - Google Analytics