暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Oracle 当外部连接11g但不是12c的许多表时ORA-01417

askTom 2018-01-08
870

问题描述

嗨,

我在12C和11g数据库中运行了以下语句。

select * from temp0101 a ,temp0101 b ,temp0101 c where 1 = 1 and a.sno = b.sno(+) and c.sno = b.sno(+);
复制


在12 C中,它成功执行,但在11i中,它抛出了以下错误。

ORA-01417: a table may be outer joined to at most one other table
01417. 00000 -  "a table may be outer joined to at most one other table"
*Cause:    a.b (+) = b.b and a.c (+) = c.c is not allowed
*Action:   Check that this is really what you want, then join b and c first
           in a view.
复制


可以知道为什么12c执行而11g不执行吗?



专家解答

那是因为它是在12c中修复的!

In previous releases of Oracle Database, in a query that performed outer joins of more than two pairs of tables, a single table could be the null-generated table for only one other table. Beginning with Oracle Database 12c, a single table can be the null-generated table for multiple tables.

Prior to Oracle Database 12c, having multiple tables on the left hand side of an outer join was illegal and resulted in an ORA-01417 error. The only way to execute such a query was to translate it into ANSI syntax. In Oracle Database 12c, the native syntax for a LEFT OUTER JOIN has been expanded to allow multiple tables on the left hand side
复制


https://docs.oracle.com/database/121/NEWFT/chapter12101.htm#NEWFT138

如文档所示,11.2中的解决方法是使用ANSI联接:

select * from temp0101 a ,temp0101 b ,temp0101 c 
where  1 = 1 
and    a.sno = b.sno(+) 
and    c.sno = b.sno(+);

ORA-01417: a table may be outer joined to at most one other table

select * from temp0101 a 
left join temp0101 b 
on a.sno = b.sno
left join temp0101 c 
on c.sno = b.sno;

SNO   NAME      SNO   NAME      SNO   NAME      
    1 Santosh       1 Santosh       1 Santosh   
    2 Santu         2 Santu         2 Santu
复制

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论