Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle Joins - Comparison between conventional syntax VS ANSI Syntax

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.

  1. Is there anything to do with limitations in application, performance, etc. while using them?
  2. What would you suggest for me?

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 (+)

  1. Also are there any freeware tools to do the rewrite?

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.

like image 933
SriniV Avatar asked Sep 19 '13 09:09

SriniV


People also ask

Can we replace the ANSI syntax with Oracle syntax in join operators?

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.

What is the difference between ANSI SQL and Oracle SQL?

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.

What is ANSI joins in Oracle?

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.

What is ANSI join 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.


1 Answers

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.

like image 152
igr Avatar answered Sep 21 '22 03:09

igr