|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Future enhancement to the WITH clause UPDATE: This has now been implemented in 11g Release 2. For more information see Recursive subquery factoring using the SQL WITH clause.
Even though it is part of the ANSI SQL standard, as of Oracle 10g, it should be noted that the WITH clause is not yet fully functional within Oracle SQL, and it does not yet support the use of WITH clause replacement for CONNECT BY when performing recursive queries.
To show how the WITH clause is used in ANSI SQL-99 syntax, the following is an excerpt from Jonathan Gennick’s work Understanding the WITH Clause showing the use of the SQL-99 WITH clause to traverse a recursive bill of materials hierarchy.
NOTE: This ANSI SQL syntax does NOT work (yet) with Oracle SQL
WITH recursiveBOM (assembly_id, assembly_name, parent_assembly) AS (SELECT parent.assembly_id, parent.assembly_name, parent.parent_assembly FROM bill_of_materials parent WHERE parent.assembly_id=100 UNION ALL SELECT child.assembly_id, child.assembly_name, child.parent_assembly FROM recursiveBOM parent, bill_of_materials child WHERE child.parent_assembly = parent.assembly_id) SELECT assembly_id, parent_assembly, assembly_name FROM recursiveBOM;
The WITH clause allows one to pre-materialize components of a complex query, making the entire query run faster. This same technique can also be used with Global temporary tables.
SEE CODE DEPOT FOR FULL SCRIPTS
http://www.rampant-books.com/book_1002_oracle_tuning_definitive_reference_2nd_ed.htm
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||