Oct 17: ANSI Join Syntax
To give the briefest of introductions, from Oracle 9i, instead of using this SQL
SELECT d.dname, e.empnoYou can use this
FROM dept d, emp e
WHERE d.deptno = e.deptno;
SELECT d.dname, e.empnoOr this
FROM dept d JOIN emp e
USING (deptno);
SELECT d.dname, e.empnoAnd instead of this pre-9i outer join
FROM dept d JOIN emp e
ON (d.deptno = e.deptno);
SELECT d.dname, e.empnoYou can use this
FROM dept d, emp e
WHERE d.deptno = e.deptno (+);
SELECT d.dname, e.empnoOr this
FROM dept d LEFT JOIN emp e
USING (deptno);
SELECT d.dname, e.empno(For more info, I googled 'Oracle ANSI join syntax' and near the top of the results was this article by Sanjay Mishra.)
FROM dept d LEFT JOIN emp e
ON (d.deptno = e.deptno);
When Oracle 9i was released I was still teaching for Learning Tree and whenever Oracle released a new major release of the rdbms, new versions of the core courses were developed. One of the key additions to the introduction course was ANSI join syntax. When I first saw this I thought :-
'Brilliant! Another thing to learn and what does it give us anyway? Database-independent applications are one of the more dangerous myths still floating around the IT industry. It also looks terribly like that long-winded ugly SQL that MS Access throws at Oracle databases I've supported. Yuck!'
Of course Oracle included the new syntax in the 9i OCP exam that covers SQL and PL/SQL, because its clearly such a critical part of being a 9i DBA, right? (No further comment.)
Then again, I'm not at all averse to learning new things and as my job was to help people learn Oracle, I had to review it properly. As I spent more time playing around with it and then teaching it, it occurred to me that I actually quite liked this alternative! The main strengths of ANSI join syntax are
- A Full Outer Join is straightforward and easy to understand when looking at the code
- The join conditions are specified where they make most sense - in the FROM clause, with the tables that you are joining.
- Although still possible, it is more unlikely that you will miss one or two join conditions in a long multi-table query. When we were discussing it, my colleague's response to this was along the lines of, 'well you wouldn't, would you?' I've had to debug enough long SQL statements with missing join conditions to prove this wrong. The problem is that there is absolutely no proper placement for join conditions in Oracle's original syntax. They can appear anywhere in the where clause, in any order, all mixed in with business logic predicates. Of course, good SQL developers impose some ordering themselves, to make their queries more readable and maintainable, but there's nothing to force them to do this. The punch-line is that it's not the good SQL developers who make the most mistakes

- Depending on the number of tables being joined, the join conditions and the particular variation of the syntax that you use, the ANSI approach can be verbose and lead to more typing. (This is probably the one that put me off most at first.)
- It's only available from 9i so if you are working with earlier versions (which many of us are, regardless of what may or may not be supported) then you would need to chop-and-change between methods. (This is the probably the biggest down-side for me now)
- I, my colleagues and most other Oracle developers and DBAs are far more familiar and comfortable with the traditional Oracle approach. (I'm sure that this is the number one reason why most people I know still use the Oracle syntax!)
Of course, I haven't
Any other opinions on this?
#1 - Sandy Mamoli said:
2005-10-17 22:01 - (Reply)
Yes, of course there are
I found a simple and compelling reason not to use ANSI syntax: There are bugs in Oracle's implementation!
For example it is not possible to select from a table which contains a CLOB column via a database link. Even if none of the CLOB columns are in the select clause you will get an "ORA-22992: cannot use LOB locators selected from remote tables" error. And it is sufficient for the remote table to just contain a CLOB column, you don't even have to select the CLOB for this error to occur.
I have an example proving this on http://www.nomad8.com/oracle_blog.html
#2 - Doug Burns said:
2005-10-17 22:15 - (Reply)
Sandy,
I think our comments crossed ![]()
Cheers,
Doug
#3 - Sandy Mamoli said:
2005-10-17 22:32 - (Reply)
Yup, I think so too
And this is the fun thing about blogging. (At least for me as a newbie blogger who is cautiosly sticking her head out of the all dominating sqlplus interface ... )
Sandy
#4 - Doug Burns said:
2005-10-17 23:12 - (Reply)
Well it looks like a pretty good effort so far and I really like the design.
Cheers,
Doug
#5 - Nuno Souto said:
2005-10-18 05:06 - (Reply)
Akshally, I'm forcing myself to use the n ANSI syntax whenever I can. Two main reasons:
1- it ain't going away and if anything it'll be seen more and more.
2- I can help iron out bugs (sorry - "unintentional features") and get familiar with them anyway.
#6 - APC said:
2005-10-18 07:40 - (Reply)
One thing for the PRO column - the FULL OUTER JOIN is definitely easier to read than a UNION of an old-style left and old-style right outer join queries.
On the CON side, the NATURAL JOIN syntax is evil, simply a bug waiting to happen.
#7 - Jeffrey Kemp said:
2005-10-18 09:58 - (Reply)
My $0.02:
I've found the ANSI join syntax much easier to work with. Of course, I've avoided the NATURAL JOIN like the plague, and have also avoided the USING variant. The biggest driver for me is the greater flexibility when you want multiple left outer joins, and the ease of doing a full outer join.
I've had to work with some monster legacy SQL in 7.3 and 8i, and those joins between 10+ tables would have taken half the time to debug if the dozen-or-so equijoins had been visually separated from the other dozen-or-so filter predicates.
I don't always use them, if the result is less readable; but generally I've found them to be a little simpler to maintain.
(This will make some of you gag: at one point I played with the idea of putting ALL the predicates in the ON clauses. The result had the advantage that the filter predicates were grouped by the table they were applied to. However, it just looked a bit messy so I've gone back to using the WHERE clause for the filters)
#8 - Doug Burns said:
2005-10-18 20:01 - (Reply)
I knew this one was likely to draw comments ![]()
Some interesting points on another blog here, including more Cons to the ANSI approach
http://oramossoracle.blogspot.com/2005/10/ansi-sql99-join-standard-yuk.html
Cheers,
Doug
#9 - Anonymous 2005-10-18 20:13 - (Reply)
Well Doug...you are correct. I't definetly aint going anywhere - especially if your teaching for the Tree. It is always a bump in the road in 590 and 593.
Good to see you have a blog...I will be a regular visitor.
Cheers
#10 - Doug Burns said:
2005-10-18 23:42 - (Reply)
Hi Jason,
Good to hear from you.
As you know, it's a strange thing being an instructor because you have to look at things with fresh eyes where possible and think what's best for your students, but your experience (which they're also looking for) can make that hard to do.
I'll reply to your email later.
Cheers,
Doug
#11 - Shaun 2007-04-13 16:58 - (Reply)
I've been looking forward to my company upgrading all our severs to 9i for some time in part so I could use the ANSI 92 standard join syntax.
The ANSI 92 standard join was the join syntax I learned working in the DB2 and SQLSever environments before I was fortunate enough to be hired by an Oracle shop. Until I got here, I had never even HEARD of putting a "(+)" in your WHERE clause to do an outer join! The "FROM ... tablea LEFT JOIN tableb ON (...)" was the only syntax I knew. I spent a whole day trying to figure out why my first outer join in the Oracle 8i environment wouldn't work.
I could be wrong, but I don't think DB2 or SQLSever will even accept the "(+)" syntax! Using the FROM clause syntax for an outer join is the way the rest of the world has been doing outer joins for a very long time. It's high time Oracle adapted to the ANSI 92 standard.
#12 - Paul Wallington 2007-11-19 17:13 - (Reply)
Hi,
First things first... great site.
I have recently moved to Oracle 9i from SQL Server (7, 2000, 2005) so am currently in the process of unlearning T-SQL in favour of PL/SQL. Must say that I am glad not to be using 8i if ANSI joining is not supported. I haven't used "Legacy" joins since my FoxPro 2.6 days
I must say that I agree with Shaun here. The ANSI 92 standard is by far the best way to join two or more tables. Structured Query Language, whatever the flavour, should be just that... Structured... the "where" clause should be used simply to limit the record set returned.
There are many reasons for this (query optimisation, asthetics so on so forth) but mainly because it is the recognised standard and has been for years.
I recognise that this thread has been going for a fair while now so would be interesting to hear what people think now...
#12.1 - Doug Burns said:
2007-11-19 19:03 - (Reply)
Paul,
Structured Query Language, whatever the flavour, should be just that... Structured... the "where" clause should be used simply to limit the record set returned.
From a logical point of view, remembered from my days teaching this, I tend to agree with you.
However, Oracle shot themselves in the foot on this one by implementing what was a big change for long-term Oracle users and then screwing it up with bugs. So a syntax that was already unfamiliar became unreliable too.
I wouldn't expect too many comments on such an old thread. Nature of the blogging beast, I'm afraid ![]()

