Oracle outer join with filter condition on the second table

巧了我就是萌 提交于 2020-01-03 05:23:29

问题


Is there any condition under which the result sets will be different from the following two statements?

select  * from a,b where a.id = b.id and b.name = 'XYZ'
select  * from a,b where a.id =b.id(+) and b.name = 'XYZ'

I think in both cases it will bring the common rows from a and b where b.name = 'XYZ'. So a.id = b.id(+) has no meaning.


回答1:


No, there is no condition under which the result sets will be different.

But your assumption "a.id = b.id(+) has no meaning" is not 100% correct. It has a meaning, because it defines the join, otherwise this would be a cartesian product of a and b with all rows from a and b.name = 'XYZ'.

What has no effect is the (+), because the statement is "semantically" wrong. It makes no sense to outer join on id but to join on name.

Usually something like that is wanted:

select  * from a,b where a.id =b.id(+) and b.name(+) = 'XYZ';

Short example at http://www.sqlfiddle.com/#!4/d19b4/15



来源:https://stackoverflow.com/questions/11568425/oracle-outer-join-with-filter-condition-on-the-second-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!