ORA-01791: not a SELECTed expression after upgrade to 11.2.0.4 (文档 ID 1600974.1)

本文讨论了在升级到Oracle数据库11.2.0.4版本后,使用select distinct查询时遇到的问题,特别是在order by子句中不引用select列表项的情况下出现ORA-01791错误。提供了正确的解决方案和原因分析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



单击此项可添加到收藏夹转到底部转到底部

In this Document

Symptoms
 Changes
 Cause
 Solution
 References

APPLIES TO:

Oracle Database - Enterprise Edition - Version 11.2.0.4 and later
Information in this document applies to any platform.

SYMPTOMS

a select DISTINCT query and the order by column does not reference a select list item after upgrade to 11.2.0.4

SQL> select distinct sal, empno from scott.emp order by deptno;
select distinct sal, empno from scott.emp order by deptno
                                                   *
ERROR at line 1:
ORA-01791: not a SELECTed expression

But it was working on previous release ..

SQL> select distinct sal, empno from scott.emp order by deptno;

       SAL      EMPNO
---------- ----------
      2450       7782
      5000       7839

 

CHANGES

 upgrade to 11.2.0.4

CAUSE

 The issue have been investigated in the following bug:

Bug:17655864 - ORA-01791: NOT A SELECTED EXPRESSION AFTER 11.2.0.4 PATCH

which is closed as not a bug. and this is expected behvior .

so the correct behavior is on 11.2.0.4 and not older versions.

This is due to 

BUG 13768663 - SELECT WORKS IN 10.2 AND 11.2.0.3 FAILS 11.1.0.7 ORA-01791

Invalid query which should raise ORA-1791 is working fine without any error starting from 11.2.0.1.This is fixed in 11.2.0.4 and hence you may get the error ORA-1791 in 11.2.0.4.

SOLUTION

The expected behaviour for this statement is that it should report ORA-01791 That is, this is a select DISTINCT query and the order by column does not reference a select list item. This is a documented restriction of the order by clause.

 

This behaviour is corrected through bugfix 13768663.

so please add the orderby column in the select statement

SQL> select distinct sal, empno, deptno from scott.emp order by deptno;

       SAL      EMPNO     DEPTNO
---------- ---------- ----------
      2450       7782         10
      5000       7839         10
      1300       7934         10

REFERENCES

BUG:17655864 - ORA-01791: NOT A SELECTED EXPRESSION AFTER 11.2.0.4 PATCH
NOTE:13768663.8 - Bug 13768663 - ORA-1791 not reported in 11.2 when expected
BUG:13768663 - SELECT WORKS IN 10.2 AND 11.2.0.3 FAILS 11.1.0.7 ORA-01791

In this Document

Symptoms
 Changes
 Cause
 Solution
 References

APPLIES TO:

Oracle Database - Enterprise Edition - Version 11.2.0.4 and later
Information in this document applies to any platform.

SYMPTOMS

a select DISTINCT query and the order by column does not reference a select list item after upgrade to 11.2.0.4

SQL> select distinct sal, empno from scott.emp order by deptno;
select distinct sal, empno from scott.emp order by deptno
                                                   *
ERROR at line 1:
ORA-01791: not a SELECTed expression

But it was working on previous release ..

SQL> select distinct sal, empno from scott.emp order by deptno;

       SAL      EMPNO
---------- ----------
      2450       7782
      5000       7839

 

CHANGES

 upgrade to 11.2.0.4

CAUSE

 The issue have been investigated in the following bug:

Bug:17655864 - ORA-01791: NOT A SELECTED EXPRESSION AFTER 11.2.0.4 PATCH

which is closed as not a bug. and this is expected behvior .

so the correct behavior is on 11.2.0.4 and not older versions.

This is due to 

BUG 13768663 - SELECT WORKS IN 10.2 AND 11.2.0.3 FAILS 11.1.0.7 ORA-01791

Invalid query which should raise ORA-1791 is working fine without any error starting from 11.2.0.1.This is fixed in 11.2.0.4 and hence you may get the error ORA-1791 in 11.2.0.4.

SOLUTION

The expected behaviour for this statement is that it should report ORA-01791 That is, this is a select DISTINCT query and the order by column does not reference a select list item. This is a documented restriction of the order by clause.

 

This behaviour is corrected through bugfix 13768663.

so please add the orderby column in the select statement

SQL> select distinct sal, empno, deptno from scott.emp order by deptno;

       SAL      EMPNO     DEPTNO
---------- ---------- ----------
      2450       7782         10
      5000       7839         10
      1300       7934         10

REFERENCES

BUG:17655864 - ORA-01791: NOT A SELECTED EXPRESSION AFTER 11.2.0.4 PATCH
NOTE:13768663.8 - Bug 13768663 - ORA-1791 not reported in 11.2 when expected
BUG:13768663 - SELECT WORKS IN 10.2 AND 11.2.0.3 FAILS 11.1.0.7 ORA-01791
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值