Oracle 11g下 ORA-01417的解决办法

  今天有兄弟反馈,有一条SQL在12C上没有问题,在11g上就报错,报错内容是ORA-01417: 表可以外部连接到至多一个其他的表。分析了下SQL,抽象为下列的例子。

在12c下没有问题:

SQL> select * from v$version;

BANNER                                                                               CON_ID
-------------------------------------------------------------------------------- ----------
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production              0
PL/SQL Release 12.1.0.1.0 - Production                                                    0
CORE    12.1.0.1.0      Production                                                        0
TNS for Linux: Version 12.1.0.1.0 - Production                                            0
NLSRTL Version 12.1.0.1.0 - Production                                                    0
drop table test1 purge;
drop table test2 purge;
drop table test3 purge;
create table test1 (id number primary key);
create table test2 (id number);
create table test3 (dept_id number,measure_id number);
insert into test1 values(1);
insert into test1 values(2);
insert into test1 values(3);
insert into test2 values(10);
insert into test2 values(20);
insert into test3 values(1,10);
commit;

SQL> select *
      from test1, test2, test3
     where test1.id = test3.dept_id(+)
       and test2.id = test3.measure_id(+);
        ID         ID    DEPT_ID MEASURE_ID
---------- ---------- ---------- ----------
         1         10          1         10
         2         10
         2         20
         3         20
         1         20
         3         10
已选择6行。


在11g下有问题:

SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE    11.2.0.1.0      Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
SQL> select *
      from test1, test2, test3
     where test1.id = test3.dept_id(+)
       and test2.id = test3.measure_id(+);
 where test1.id = test3.dept_id(+)
                *
第 3 行出现错误:
ORA-01417: 表可以外部连接到至多一个其他的表

--把test1和test2联合起来,再与test3关联,问题解决

SQL> select *
      from (select test1.id dept_id, test2.id measure_id from test1, test2) a,
           test3
     where a.dept_id = test3.dept_id(+)
       and a.measure_id = test3.measure_id(+);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值