Preamble
As of late, I see too many geeks commenting on Oracle questions saying "Do not use (+) operator, rather use JOIN syntax".
Question
I do see that both work well. But what is the real difference between using them? I would welcome answers more from experience.
I did read something on Oracle documentation but it’s not good enough to make me understand or feel comfortable with the comprehensive information.
Note: I am planning to migrate 200+ packages and procedures, if the Keyword should be used instead of (+)
Posting samples
┌───────────────────────────────────┬─────────────────────────────────────────────┐ │ INNER JOIN - CONVENTIONAL │ INNER JOIN - ANSI SYNTAX │ ├───────────────────────────────────┼─────────────────────────────────────────────┤ │ SELECT │ SELECT │ │ emp.deptno │ ename, │ │ FROM │ dname, │ │ emp, │ emp.deptno, │ │ dept │ dept.deptno │ │ WHERE │ FROM │ │ emp.deptno = dept.deptno; │ scott.emp INNER JOIN scott.dept │ │ │ ON emp.deptno = dept.deptno; │ ├───────────────────────────────────┼─────────────────────────────────────────────┤ │ LEFT OUTER JOIN - CONVENTIONAL │ LEFT OUTER JOIN - ANSI SYNTAX │ ├───────────────────────────────────┼─────────────────────────────────────────────┤ │ SELECT │ SELECT │ │ emp.deptno │ ename, │ │ FROM │ dname, │ │ emp, │ emp.deptno, │ │ dept │ dept.deptno │ │ WHERE │ FROM │ │ emp.deptno = dept.deptno(+); │ scott.emp LEFT OUTER JOIN scott.dept │ │ │ ON emp.deptno = dept.deptno; │ ├───────────────────────────────────┼─────────────────────────────────────────────┤ │ RIGHT OUTER JOIN - CONVENTIONAL │ RIGHT OUTER JOIN - ANSI SYNTAX │ ├───────────────────────────────────┼─────────────────────────────────────────────┤ │ SELECT │ SELECT │ │ emp.deptno │ ename, │ │ FROM │ dname, │ │ emp, │ emp.deptno, │ │ dept │ dept.deptno │ │ WHERE │ FROM │ │ emp.deptno(+) = dept.deptno; │ scott.emp RIGHT OUTER JOIN scott.dept │ │ │ ON emp.deptno = dept.deptno; │ ├───────────────────────────────────┼─────────────────────────────────────────────┤ │ FULL OUTER JOIN - CONVENTIONAL │ FULL OUTER JOIN - ANSI SYNTAX │ ├───────────────────────────────────┼─────────────────────────────────────────────┤ │ SELECT │ SELECT │ │ * │ * │ │ FROM │ FROM │ │ emp, │ scott.emp FULL OUTER JOIN scott.dept │ │ dept │ ON emp.deptno = dept.deptno; │ │ WHERE │ │ │ emp.deptno = dept.deptno(+) │ │ │ UNION ALL │ │ │ SELECT │ │ │ * │ │ │ FROM │ │ │ emp, │ │ │ dept │ │ │ WHERE │ │ │ emp.deptno(+) = dept.deptno │ │ │ AND emp.deptno IS NULL; │ │ └───────────────────────────────────┴─────────────────────────────────────────────┘
PS: Read the summary of answers for all updates grouped.
There is no direct equivalent of a full outer join using the non-ANSI join syntax, but we can recreate it by combining two outer join queries using a UNION ALL , as shown below.
ANSI is an industry standard. Some Oracle features are not ANSI compliant, either because they were added before the standard was defined (like DECODE) or because a commercial product like Oracle needs to be able to add new features (like MODEL). Basically there is syntax difference between both of them.
Oracle has introduced ANSI-compliant joins into its SQL implementation in 9i Release One (9.0). This provides an alternative syntax to joining datasets together, which can be used in conjunction, or as an alternative to, existing Oracle syntax.
ANSI join syntax allows you to write either: Inner joins, in which the joined table includes only the rows of the inner and outer tables that meet the conditions of the on clause.
If your 200+ packages work as intended with "old fashioned" syntax, let it be. SQL will not start to perform better after migration to ANSI syntax - it's just different syntax.
All that being said, ANSI syntax is cleaner - you are not going to normal join if you forget (+) in some multi-column outer join.
In the past there were some bugs with ANSI syntax but if you go with latest 11.2 or 12.1 that should be fixed already.
Of course, you know your environment and priorities better - as SchmitzIT said - ANSI syntax is part of SQL standard and it would help when going to use some other RDBMS product.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With