Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Subquery Factoring and Materialized Hint

ramarunNov 28 2012 — edited Nov 28 2012
WITH t AS
        (SELECT MAX (lDATE) tidate
           FROM rate_Master
          WHERE     Code = 'G'
                AND orno > 0
                AND TYPE = 'L'
                AND lDATE <= ':entereddate')
SELECT DECODE (:p1,  'B', RateB,  'S', RateS,  Rate)
  FROM rate_Master, t
 WHERE     Code = 'G'
       AND orno > 0
       AND TYPE = 'L'
       AND NVL (lDATE, SYSDATE) = tidate;
In the given example the sub query returns just one row because of the aggregate function max. Making this in to a With clause will be of any benefit ? Also i presume/understand that the subquery factoring would be really useful only when we try to make a sub query which returns more rows in a with clause. Is my intrepration right?

Secondly adding the /*+ Materialize */ hint to a With query is mandatory or the optimizer by itself will do it and make a temp table transformation. In my example i am forced to give the hint in the query. Please discuss and help

Thanks in advance.
This post has been answered by BluShadow on Nov 28 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 26 2012
Added on Nov 28 2012
6 comments
2,274 views