The Essentials of the (+) in oracle 11g

the (+) syntax is obsolete, proprietary syntax that Oracle used for years to accomplish the same results as an OUTER JOIN. I assume they adopted their proprietary syntax before SQL-92 decided on the standard syntax.
Using standard SQL OUTER JOIN syntax (which is now supported by all major RDBMS implementations) would be the following example:



SELECT
    Table1.Category1,
    Table1.Category2,
    COUNT(*) AS Total,
    COUNT(Table2.Stat) AS StatFROM Table1
  LEFT OUTER JOIN Table2 ON (Table1.PrimaryKey = Table2.ForeignKey)
GROUP BY Table1.Category1, Table1.Category2;



Which basically means -
  • All rows from Table1 are included in the query result.
  • Where there are matching rows in Table2, include those rows (repeating content from Table1 if there are multiple matching rows in Table2).
  • Where there are no matching rows in Table2, use NULL for all of Table2's columns in the query result.
But the essentials of this is can be rewritten to importantly shorten the code that you write especially with PLSQL ,ie



SELECT
    Table1.Category1,
    Table1.Category2,
    count(*) as Total,
    count(Tab2.Stat) AS StatFROM Table1, Table2WHERE (Table1.PrimaryKey = Table2.ForeignKey(+))
GROUP BY Table1.Category1, Table1.Category2

 Hope this helps in your daily writing of plsql and sql codes .
Benjamin Intsiful

I live on Ice Tea, an Apex gourmet and web development fanatic

Post a Comment

Previous Post Next Post