Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle 12c documentation for changes / new features to SQL

I just found out that Oracle 12c supports correlating a query several levels deep which is unsupported in 11g and previous versions.

select
   *
from
   tab1 a
where
   not exists
         (select
                *
           from
               (select
                    *
                from
                    tab2 b
                where a.X = b.X))

But I could not find this documented in Oracle website. Is there any other such hidden SQL features added to Oracle 12c? Are all such changes to SQL in 12c documented somewhere?

like image 373
toddlermenot Avatar asked May 11 '17 14:05

toddlermenot


People also ask

What is the greatest feature in Oracle Database 12c?

One of the most useful features of Oracle 12c is the ability to limit rows easily. This is great for pagination and other similar requirements. In older versions of Oracle, you needed to have one or two nested subqueries with the ROWNUM function.


1 Answers

To explain this we need to dive into history a little bit.

Ability to use correlated sub-queries with more than 1 level was also in Oracle 10g R1 and it was properly documented (https://docs.oracle.com/cd/B14117_01/server.101/b10759/queries007.htm) back those days...

Oracle performs a correlated subquery when a nested subquery references a column from a table referred to a parent statement any number of levels above the subquery.

... but it was not properly working. :)

So starting with Oracle 10g R2 this functionality was disabled and documentation had changed.

Also (if you have an access) you can see Bug 15990897 : QUERY WITH CORRELATED VARIABLE USED IN 2ND LEVEL SUBQUERY FAILS WITH ORA-904 on Metalink (Fixed in Product Version 12.1.0.1.0). I'm not sure why it's considered as a bug given that it works according to documentation (10g R2, 11g R1, 11g R2) but that is how it is.

So, functionality was disabled after 10.1 and before 12.1 but documentation even for 12.2 (https://docs.oracle.com/en/database/oracle/oracle-database/12.2/sqlrf/Using-Subqueries.html) says

Oracle performs a correlated subquery when a nested subquery references a column from a table referred to a parent statement one level above the subquery.

Cut a long story short, this functionality is enabled in 12c R1 and 12c R2 but documentation is not fixed and apparently there is no mentioning about this improvement in New Features guide.

PS. As far as I remember standard SQL 2003 allows correlation only to one level deep - everyone is welcome to check (http://www.wiscorp.com/sql_2003_standard.zip). But Oracle has a lot of improvements above the standard anyway.

like image 198
Dr Y Wit Avatar answered Oct 22 '22 01:10

Dr Y Wit