Today I was wondering about whether we should be using Ansi SQL instead of the 'normal' Oracle SQL. Ansi SQL has been supported in Oracle since version 9i, but since we are still developing applications on Oracle 8i we haven't really given it much thought until now. We are migrating our development database to Oracle9i (No 10G yet, because our DBA's don't support it yet) and now is the time to consider writing Ansi SQL instead of the 'normal' Oracle SQL.
What are the pros and cons of Ansi SQL? One of the things that pops to mind is to make our application less 'Oracle locked in'. But will we really achieve that just by using Ansi SQL? Our application(s) rely heavily on the Oracle database and all of it's features. Of course we can use Ansi SQL all the way, but a lot of functions and procedures are deliberately put in backend code (PL/SQL) because of their speed and their need for database interactivity. Sure, we can rebuild these in say SQL Server or even MySQL, but at this moment we don't use any of those for this application and frankly, I don't see this happening any time soon.
Another thing is that it may make the queries more readable. All the joins between tables are done in the FROM clause instead of in the WHERE clause. Now they can be grouped together, although I am used to writing the joins first in my WHERE clauses. But it doesn't mean everybody writes in such a way.
A problem with our current queries can definitely be the outer-joins used. In Oracle SQL you use the plus sign (+) to tell the SQL Engine that it's an outer join. In SQL Server you should use the asterisk (*) operator to do the same. In Ansi SQL you tell the query to LEFT OUTER JOIN or RIGHT OUTER JOIN one table to another. This is the same in both engines.
I don't know which syntax I like more. The Oracle SQL version:
FROM emp, dept
WHERE emp.deptno = dept.deptno;
Or the Ansi SQL version:
FROM emp JOIN dept ON emp.deptno = dept.deptno;
I think it just takes some getting used to. Of course there are possibilities in Ansi SQL that are easier to use than doing the same in 'normal' SQL. There's for instance the FULL OUTER JOIN. Show all rows from one table that may or may not have a row in the other table and vice versa. Sure this can be achieved in Oracle SQL creating a UNION based query, but that would mean that all the other clauses in the query would have to be written twice (or more), which is totally against our Single Point Of Definition principle. I know Steven Feuerstein wrote about this in one of his blogs on ToadWorld, but I think we were using this principle since the last century (somewhere in the 90's).
I am not sure what to use. Maybe it's better to start getting used to Ansi SQL because it's a better preparation for future versions of the (Oracle) database. And we can be more prepared to move to different databases, although that will include learning a new language as well as a new way to create code in the database. I know I am not a supporter of a 'dumb database' or 'datastore'. I want to use the features in the database as they are available.