Subquery Factoring Help Needed

Newb question here...
The following query with it's contained subquery's (With) does not seem to be working correctly.
In particular, the subquery titled "INSTANCES" wich is referenced 3 times (in the TRENDS, UNKNOWNS, and STARTS subquery) seems to provide no data when it is used in the "TRENDS" subquery as the end result gives me only one row, the row from the "STARTS" subquery.
If I duplicate the INSTANCES subquery 3 times so that each subquery is only referenced once, I get all the expected data in the TRENDS subquery....obviously this is not ideal..
Any insight is much appreciated.
Background info:
1. This query is used in HP Quality Center. The database reference is located here: http://support.openview.hp.com/selfsolve/document/KM749209/binary/QC10_DataBaseRefernce.zip?searchIdentifier=-5b22d9a5%3a126f600a568%3a-5b1a&resultType=document
2. Strings contained in @ symbols are parameters inserted into the query by Quality Center.
3. I have access only to SQL, no stored procedures or functions of any kind alllowed.
3. Oracle version is 10g - 10.2.0.3.0
4. I wouldn't consider myself an expert at SQL at all....other opimizations to this query would be welcome...
SELECT DT "DATE",
  SUM(NA) OVER (PARTITION BY TREND ORDER BY DT) NA,
  SUM(EXCLUDED) OVER (PARTITION BY TREND ORDER BY DT) EXCLUDED,
  SUM(BLOCKED) OVER (PARTITION BY TREND ORDER BY DT) BLOCKED,
  SUM(NOT_COMPLETED) OVER (PARTITION BY TREND ORDER BY DT) NOT_COMPLETED,
  SUM(NO_RUN) OVER (PARTITION BY TREND ORDER BY DT) NO_RUN,
  SUM(FAILED) OVER (PARTITION BY TREND ORDER BY DT) FAILED,
  SUM(PASSED) OVER (PARTITION BY TREND ORDER BY DT) PASSED,
  ((SUM(FAILED) OVER (PARTITION BY TREND ORDER BY DT)) + (SUM(PASSED) OVER (PARTITION BY TREND ORDER BY DT))) ATTEMPTED
  FROM
      WITH TSF_PATHS AS(
        SELECT CF_ITEM_PATH AS PATH FROM CYCL_FOLD WHERE CF_ITEM_ID IN ( @TestSet_Folder_ID@ )
      ), INSTANCES AS (
        SELECT TESTCYCL.TC_TESTCYCL_ID, RELEASE_CYCLES.RCYC_ID RCID FROM TESTCYCL
        JOIN CYCLE ON CYCLE.CY_CYCLE_ID=TESTCYCL.TC_CYCLE_ID
        LEFT JOIN RELEASE_CYCLES ON CYCLE.CY_ASSIGN_RCYC=RELEASE_CYCLES.RCYC_ID
        LEFT JOIN RELEASES ON RELEASE_CYCLES.RCYC_PARENT_ID=RELEASES.REL_ID
        JOIN TEST ON TEST.TS_TEST_ID=TESTCYCL.TC_TEST_ID
        WHERE CYCLE.CY_FOLDER_ID IN (SELECT CF_ITEM_ID FROM CYCL_FOLD, TSF_PATHS WHERE CF_ITEM_PATH LIKE TSF_PATHS.PATH || '%')
      ), TRENDS AS (
        SELECT 'TREND' TREND, DT,
          SUM(NOT_COMPLETED) NOT_COMPLETED,
          SUM(NO_RUN) NO_RUN,
          SUM(FAILED) FAILED,
          SUM(PASSED) PASSED,
          SUM(BLOCKED) BLOCKED,
          SUM(EXCLUDED) EXCLUDED,
          SUM(NA) NA
          FROM (
            SELECT TO_CHAR(AU_TIME, 'yyyy-mm-dd') DT,
              DECODE(AP_OLD_VALUE, 'Not Completed', -1, 0) + DECODE(AP_NEW_VALUE, 'Not Completed', 1, 0) NOT_COMPLETED,
              DECODE(AP_OLD_VALUE, 'No Run', -1, 0) + DECODE(AP_NEW_VALUE, 'No Run', 1, 0) NO_RUN,
              DECODE(AP_OLD_VALUE, 'Failed', -1, 0) + DECODE(AP_NEW_VALUE, 'Failed', 1, 0) FAILED,
              DECODE(AP_OLD_VALUE, 'Passed', -1, 0) + DECODE(AP_NEW_VALUE, 'Passed', 1, 0) PASSED,
              DECODE(AP_OLD_VALUE, 'Blocked', -1, 0) + DECODE(AP_NEW_VALUE, 'Blocked', 1, 0) BLOCKED,
              DECODE(AP_OLD_VALUE, 'Excluded', -1, 0) + DECODE(AP_NEW_VALUE, 'Excluded', 1, 0) EXCLUDED,
              DECODE(AP_OLD_VALUE, 'N/A', -1, 0) + DECODE(AP_NEW_VALUE, 'N/A', 1, 0) NA
            FROM AUDIT_LOG
            JOIN AUDIT_PROPERTIES ON AUDIT_LOG.AU_ACTION_ID=AUDIT_PROPERTIES.AP_ACTION_ID
            WHERE AU_ENTITY_ID IN ( SELECT TC_TESTCYCL_ID FROM INSTANCES )
            AND AU_ENTITY_TYPE='TESTCYCL'
            AND AP_FIELD_NAME='TC_STATUS'
        GROUP BY DT
        ORDER BY DT
      ), UNKNOWNS AS (
        SELECT COUNT(DISTINCT AU_ENTITY_ID) CNT
            FROM AUDIT_LOG
            JOIN AUDIT_PROPERTIES ON AUDIT_LOG.AU_ACTION_ID=AUDIT_PROPERTIES.AP_ACTION_ID
            WHERE AU_ENTITY_ID IN ( SELECT TC_TESTCYCL_ID FROM INSTANCES )
            AND AU_ENTITY_TYPE='TESTCYCL'
            AND AP_FIELD_NAME='TC_STATUS'
            AND DECODE(AP_OLD_VALUE, 'No Run', 0, 'Not Completed', 0, 'Failed', 0, 'Passed', 0, 'Blocked', 0, 'Excluded', 0, 'N/A', 0, 1) = 1
            AND AP_NEW_VALUE='No Run'
      ), STARTS AS (
        SELECT 'TREND' Trend, TO_CHAR(TO_DATE((SELECT DT FROM TRENDS WHERE ROWNUM=1), 'yyyy-mm-dd')-1, 'yyyy-mm-dd') DT, 0 NOT_COMPLETED, (SELECT COUNT(*) FROM INSTANCES)-(SELECT CNT FROM UNKNOWNS WHERE ROWNUM=1) NO_RUN, 0 FAILED, 0 PASSED, 0 BLOCKED, 0 EXCLUDED, 0 NA FROM DUAL
      SELECT * FROM STARTS
      UNION ALL
      SELECT * FROM TRENDS
)Edited by: user9191784 on Feb 22, 2010 9:36 AM

Lakmal,
Unfortunately, my hands are tied in Quality Center such that I can only use SQL queries that begin with "Select". As a result my queries have to be in the form:
SELECT * FROM (
  WITH X AS (....)
  SELECT ... FROM X
)Frank,
I have taken your approach and ensured each subquery works on it's own.
Here is some more info that might be useful though...
I tried to simplify the query to make it more user friendly and in doing so left out something that might reveal the underlying issue. Here is my original query below(using your suggestion to remove the in-line view).
You'll notice several parameters in the where statement in the INSTANCES subquery. Each parameter has a default value of -1 and in most situations, only one of these parameters will be used.
Here's the kicker....If I use an ID in the @Testset_Folder_Parameter@, the query works just fine. But if I use an ID in one of the other Paramters, I only get my data from the STARTS subquery and other references to the INSTANCES subquery seem to return no rows, as a result TREND_DATA is empty.
I'll try and add create/insert statements when I have time. It will have to be on the base tables, becuase as I mentioned, all subqueries work when executed alone, this issue only appears when I reference the INSTANCES subquery multiple times and when one of the parameters of ther than @TestSet_Folder_ID@ is used...
SELECT DT "DATE",
  SUM(NA) OVER (PARTITION BY TREND ORDER BY DT) NA,
  SUM(EXCLUDED) OVER (PARTITION BY TREND ORDER BY DT) EXCLUDED,
  SUM(BLOCKED) OVER (PARTITION BY TREND ORDER BY DT) BLOCKED,
  SUM(NOT_COMPLETED) OVER (PARTITION BY TREND ORDER BY DT) NOT_COMPLETED,
  SUM(NO_RUN) OVER (PARTITION BY TREND ORDER BY DT) NO_RUN,
  SUM(FAILED) OVER (PARTITION BY TREND ORDER BY DT) FAILED,
  SUM(PASSED) OVER (PARTITION BY TREND ORDER BY DT) PASSED,
  ((SUM(FAILED) OVER (PARTITION BY TREND ORDER BY DT)) + (SUM(PASSED) OVER (PARTITION BY TREND ORDER BY DT))) ATTEMPTED
  FROM
      WITH TSF_PATHS AS(
        SELECT CF_ITEM_PATH AS PATH FROM CYCL_FOLD WHERE CF_ITEM_ID IN ( @TestSet_Folder_ID@ )
      ),INSTANCES AS (
        SELECT TESTCYCL.TC_TESTCYCL_ID, RELEASE_CYCLES.RCYC_ID RCID FROM TESTCYCL
        JOIN CYCLE ON CYCLE.CY_CYCLE_ID=TESTCYCL.TC_CYCLE_ID
        LEFT JOIN RELEASE_CYCLES ON CYCLE.CY_ASSIGN_RCYC=RELEASE_CYCLES.RCYC_ID
        LEFT JOIN RELEASES ON RELEASE_CYCLES.RCYC_PARENT_ID=RELEASES.REL_ID
        JOIN TEST ON TEST.TS_TEST_ID=TESTCYCL.TC_TEST_ID
        WHERE  CY_ASSIGN_RCYC IN ( @CYCLE_ID@ )
          OR CYCLE.CY_FOLDER_ID IN (SELECT CF_ITEM_ID FROM CYCL_FOLD, TSF_PATHS WHERE CF_ITEM_PATH LIKE TSF_PATHS.PATH || '%')
          OR RELEASE_CYCLES.RCYC_PARENT_ID IN ( @Release_ID@ )
          OR RELEASES.REL_USER_06 IN ( @Ticket_ID@ )
      ), TREND_DATA AS(
        SELECT TO_CHAR(AU_TIME, 'yyyy-mm-dd') DT,
          DECODE(AP_OLD_VALUE, 'Not Completed', -1, 0) + DECODE(AP_NEW_VALUE, 'Not Completed', 1, 0) NOT_COMPLETED,
          DECODE(AP_OLD_VALUE, 'No Run', -1, 0) + DECODE(AP_NEW_VALUE, 'No Run', 1, 0) NO_RUN,
          DECODE(AP_OLD_VALUE, 'Failed', -1, 0) + DECODE(AP_NEW_VALUE, 'Failed', 1, 0) FAILED,
          DECODE(AP_OLD_VALUE, 'Passed', -1, 0) + DECODE(AP_NEW_VALUE, 'Passed', 1, 0) PASSED,
          DECODE(AP_OLD_VALUE, 'Blocked', -1, 0) + DECODE(AP_NEW_VALUE, 'Blocked', 1, 0) BLOCKED,
          DECODE(AP_OLD_VALUE, 'Excluded', -1, 0) + DECODE(AP_NEW_VALUE, 'Excluded', 1, 0) EXCLUDED,
          DECODE(AP_OLD_VALUE, 'N/A', -1, 0) + DECODE(AP_NEW_VALUE, 'N/A', 1, 0) NA
        FROM AUDIT_LOG
        JOIN AUDIT_PROPERTIES ON AUDIT_LOG.AU_ACTION_ID=AUDIT_PROPERTIES.AP_ACTION_ID
        WHERE AU_ENTITY_ID IN ( SELECT TC_TESTCYCL_ID FROM INSTANCES )
        AND AU_ENTITY_TYPE='TESTCYCL'
        AND AP_FIELD_NAME='TC_STATUS'
      ), TRENDS AS (
        SELECT 'TREND' TREND, DT,
          SUM(NOT_COMPLETED) NOT_COMPLETED,
          SUM(NO_RUN) NO_RUN,
          SUM(FAILED) FAILED,
          SUM(PASSED) PASSED,
          SUM(BLOCKED) BLOCKED,
          SUM(EXCLUDED) EXCLUDED,
          SUM(NA) NA
        FROM TREND_DATA
        GROUP BY DT
        ORDER BY DT
      ), UNKNOWNS AS (
        SELECT COUNT(DISTINCT AU_ENTITY_ID) CNT
            FROM AUDIT_LOG
            JOIN AUDIT_PROPERTIES ON AUDIT_LOG.AU_ACTION_ID=AUDIT_PROPERTIES.AP_ACTION_ID
            WHERE AU_ENTITY_ID IN ( SELECT TC_TESTCYCL_ID FROM INSTANCES )
            AND AU_ENTITY_TYPE='TESTCYCL'
            AND AP_FIELD_NAME='TC_STATUS'
            AND DECODE(AP_OLD_VALUE, 'No Run', 0, 'Not Completed', 0, 'Failed', 0, 'Passed', 0, 'Blocked', 0, 'Excluded', 0, 'N/A', 0, 1) = 1
            AND AP_NEW_VALUE='No Run'
      ), STARTS AS (
        SELECT 'TREND' Trend, TO_CHAR(TO_DATE((SELECT DT FROM TRENDS WHERE ROWNUM=1), 'yyyy-mm-dd')-1, 'yyyy-mm-dd') DT, 0 NOT_COMPLETED, (SELECT COUNT(*) FROM INSTANCES)-(SELECT CNT FROM UNKNOWNS WHERE ROWNUM=1) NO_RUN, 0 FAILED, 0 PASSED, 0 BLOCKED, 0 EXCLUDED, 0 NA FROM DUAL
      SELECT * FROM STARTS
      UNION ALL
      SELECT * FROM TRENDS)What has me baffled is that the following query works just fine. I've just duplicated the INSTANCES subquery, once for each time it is used in the following queries.
SELECT DT "DATE",
  SUM(NA) OVER (PARTITION BY TREND ORDER BY DT) NA,
  SUM(EXCLUDED) OVER (PARTITION BY TREND ORDER BY DT) EXCLUDED,
  SUM(BLOCKED) OVER (PARTITION BY TREND ORDER BY DT) BLOCKED,
  SUM(NOT_COMPLETED) OVER (PARTITION BY TREND ORDER BY DT) NOT_COMPLETED,
  SUM(NO_RUN) OVER (PARTITION BY TREND ORDER BY DT) NO_RUN,
  SUM(FAILED) OVER (PARTITION BY TREND ORDER BY DT) FAILED,
  SUM(PASSED) OVER (PARTITION BY TREND ORDER BY DT) PASSED,
  ((SUM(FAILED) OVER (PARTITION BY TREND ORDER BY DT)) + (SUM(PASSED) OVER (PARTITION BY TREND ORDER BY DT))) ATTEMPTED
  FROM
      WITH TSF_PATHS AS(
        SELECT CF_ITEM_PATH AS PATH FROM CYCL_FOLD WHERE CF_ITEM_ID IN ( @TestSet_Folder_ID@ )
      ),INSTANCES AS (
        SELECT TESTCYCL.TC_TESTCYCL_ID, RELEASE_CYCLES.RCYC_ID RCID FROM TESTCYCL
        JOIN CYCLE ON CYCLE.CY_CYCLE_ID=TESTCYCL.TC_CYCLE_ID
        LEFT JOIN RELEASE_CYCLES ON CYCLE.CY_ASSIGN_RCYC=RELEASE_CYCLES.RCYC_ID
        LEFT JOIN RELEASES ON RELEASE_CYCLES.RCYC_PARENT_ID=RELEASES.REL_ID
        JOIN TEST ON TEST.TS_TEST_ID=TESTCYCL.TC_TEST_ID
        WHERE  CY_ASSIGN_RCYC IN ( @CYCLE_ID@ )
          OR CYCLE.CY_FOLDER_ID IN (SELECT CF_ITEM_ID FROM CYCL_FOLD, TSF_PATHS WHERE CF_ITEM_PATH LIKE TSF_PATHS.PATH || '%')
          OR RELEASE_CYCLES.RCYC_PARENT_ID IN ( @Release_ID@ )
          OR RELEASES.REL_USER_06 IN ( @Ticket_ID@ )
      ),INSTANCES2 AS (
        SELECT TESTCYCL.TC_TESTCYCL_ID, RELEASE_CYCLES.RCYC_ID RCID FROM TESTCYCL
        JOIN CYCLE ON CYCLE.CY_CYCLE_ID=TESTCYCL.TC_CYCLE_ID
        LEFT JOIN RELEASE_CYCLES ON CYCLE.CY_ASSIGN_RCYC=RELEASE_CYCLES.RCYC_ID
        LEFT JOIN RELEASES ON RELEASE_CYCLES.RCYC_PARENT_ID=RELEASES.REL_ID
        JOIN TEST ON TEST.TS_TEST_ID=TESTCYCL.TC_TEST_ID
        WHERE  CY_ASSIGN_RCYC IN ( @CYCLE_ID@ )
          OR CYCLE.CY_FOLDER_ID IN (SELECT CF_ITEM_ID FROM CYCL_FOLD, TSF_PATHS WHERE CF_ITEM_PATH LIKE TSF_PATHS.PATH || '%')
          OR RELEASE_CYCLES.RCYC_PARENT_ID IN ( @Release_ID@ )
          OR RELEASES.REL_USER_06 IN ( @Ticket_ID@ )
      ),INSTANCES3 AS (
        SELECT TESTCYCL.TC_TESTCYCL_ID, RELEASE_CYCLES.RCYC_ID RCID FROM TESTCYCL
        JOIN CYCLE ON CYCLE.CY_CYCLE_ID=TESTCYCL.TC_CYCLE_ID
        LEFT JOIN RELEASE_CYCLES ON CYCLE.CY_ASSIGN_RCYC=RELEASE_CYCLES.RCYC_ID
        LEFT JOIN RELEASES ON RELEASE_CYCLES.RCYC_PARENT_ID=RELEASES.REL_ID
        JOIN TEST ON TEST.TS_TEST_ID=TESTCYCL.TC_TEST_ID
        WHERE  CY_ASSIGN_RCYC IN ( @CYCLE_ID@ )
          OR CYCLE.CY_FOLDER_ID IN (SELECT CF_ITEM_ID FROM CYCL_FOLD, TSF_PATHS WHERE CF_ITEM_PATH LIKE TSF_PATHS.PATH || '%')
          OR RELEASE_CYCLES.RCYC_PARENT_ID IN ( @Release_ID@ )
          OR RELEASES.REL_USER_06 IN ( @Ticket_ID@ )
      ), TREND_DATA AS(
        SELECT TO_CHAR(AU_TIME, 'yyyy-mm-dd') DT,
          DECODE(AP_OLD_VALUE, 'Not Completed', -1, 0) + DECODE(AP_NEW_VALUE, 'Not Completed', 1, 0) NOT_COMPLETED,
          DECODE(AP_OLD_VALUE, 'No Run', -1, 0) + DECODE(AP_NEW_VALUE, 'No Run', 1, 0) NO_RUN,
          DECODE(AP_OLD_VALUE, 'Failed', -1, 0) + DECODE(AP_NEW_VALUE, 'Failed', 1, 0) FAILED,
          DECODE(AP_OLD_VALUE, 'Passed', -1, 0) + DECODE(AP_NEW_VALUE, 'Passed', 1, 0) PASSED,
          DECODE(AP_OLD_VALUE, 'Blocked', -1, 0) + DECODE(AP_NEW_VALUE, 'Blocked', 1, 0) BLOCKED,
          DECODE(AP_OLD_VALUE, 'Excluded', -1, 0) + DECODE(AP_NEW_VALUE, 'Excluded', 1, 0) EXCLUDED,
          DECODE(AP_OLD_VALUE, 'N/A', -1, 0) + DECODE(AP_NEW_VALUE, 'N/A', 1, 0) NA
        FROM AUDIT_LOG
        JOIN AUDIT_PROPERTIES ON AUDIT_LOG.AU_ACTION_ID=AUDIT_PROPERTIES.AP_ACTION_ID
        WHERE AU_ENTITY_ID IN ( SELECT TC_TESTCYCL_ID FROM INSTANCES )
        AND AU_ENTITY_TYPE='TESTCYCL'
        AND AP_FIELD_NAME='TC_STATUS'
      ), TRENDS AS (
        SELECT 'TREND' TREND, DT,
          SUM(NOT_COMPLETED) NOT_COMPLETED,
          SUM(NO_RUN) NO_RUN,
          SUM(FAILED) FAILED,
          SUM(PASSED) PASSED,
          SUM(BLOCKED) BLOCKED,
          SUM(EXCLUDED) EXCLUDED,
          SUM(NA) NA
        FROM TREND_DATA
        GROUP BY DT
        ORDER BY DT
      ), UNKNOWNS AS (
        SELECT COUNT(DISTINCT AU_ENTITY_ID) CNT
            FROM AUDIT_LOG
            JOIN AUDIT_PROPERTIES ON AUDIT_LOG.AU_ACTION_ID=AUDIT_PROPERTIES.AP_ACTION_ID
            WHERE AU_ENTITY_ID IN ( SELECT TC_TESTCYCL_ID FROM INSTANCES2 )
            AND AU_ENTITY_TYPE='TESTCYCL'
            AND AP_FIELD_NAME='TC_STATUS'
            AND DECODE(AP_OLD_VALUE, 'No Run', 0, 'Not Completed', 0, 'Failed', 0, 'Passed', 0, 'Blocked', 0, 'Excluded', 0, 'N/A', 0, 1) = 1
            AND AP_NEW_VALUE='No Run'
      ), STARTS AS (
        SELECT 'TREND' Trend, TO_CHAR(TO_DATE((SELECT DT FROM TRENDS WHERE ROWNUM=1), 'yyyy-mm-dd')-1, 'yyyy-mm-dd') DT, 0 NOT_COMPLETED, (SELECT COUNT(*) FROM INSTANCES3)-(SELECT CNT FROM UNKNOWNS WHERE ROWNUM=1) NO_RUN, 0 FAILED, 0 PASSED, 0 BLOCKED, 0 EXCLUDED, 0 NA FROM DUAL
      SELECT * FROM STARTS
      UNION ALL
      SELECT * FROM TRENDS)

Similar Messages

  • How to use subquery factoring ("with" clause) in OWB?

    Hi,
    Is it possible to use subquery factoring (popularly known as "with" clause) in OWB 10gR2? I have a mapping with a splitter and union-all, which generates a query that has repeated scans of the same table. Subquery Factoring would be very useful here. I think this is a very common situation, so, I hope there's a way to achieve this. (If not in this version, this would be my wishlist item for the next version.)
    Appreciate your help.
    Regards,
    Rahul

    Hi Rahul,
    I'm afraid you have to put this on your wishlist. You may put the query with the "with"-clause into a view (or table function if you need parameters) if performance is too bad. But that is somehow against the idea (and benefits) of owb.
    Another possibility is to use a temporary table and spilt the mappings into two parts: first fill the temp table, then the target table.
    Regards,
    Carsten.

  • Subquery Factoring and Materialized Hint

    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.

    ramarun wrote:
    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?I am not aware of any performance Benefit due to use of With clause. IMO, It eases the job to write a Subquery multiple times in a query.
    The solution you adopted has to hit the cache twice and hence do not look very performant. I will advise you to opt for Analytic functions (like the suggestion I provided in another thread). If the solution does not yeild correct results, then provide with a Script that we can replicate (Create table, Sample Insert statement and the expected output).
    select decode(:p1, 'B', RateB, 'S', RateS, Rate)
       from (
                select RateB, RateS, Rate, NVL(ldate, sysdate) ldate, dense_rank() over (order by case when NVL(lDATE, SYSDATE) <= ':entereddate' then NVL(lDATE, SYSDATE) else to_date('01/01/1970', 'DD/MM/YYYY' end DESC) rn
                  from rate_Master
               where Code = 'G'
                   and orno > 0
                   and type = 'L'
             ) a
      where a.rn = 1;>
    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
    Usage of Hints is only for Debugging purposes and is not meant to be used in production code. It is when you have to ascertain the reason for CBO choosing a plan that you do not expect it to take, you use hints to force your plan and find the cost and analyze it. Hence, I do not support the idea of Hints for production code.

  • Help needed using adobe exportpdf

    The first time I used adobe export pdf it worked well. However the next time and every other time I try to convert a pdf doc to word docx I get the error message at the end of the uploading session. "pdf doc failed to export to m,icrosoft word.  There was an unexpected problem.
    Anyone overcome this problem?

    Hi Stacy
                   Thanks for that info.  I was aware of the 100MB limit but 
    your response made me think again and go back to the problem and this is 
    what I found. The first  pdf document I uploaded into Adobe export pdf was  43
    MB and it went through fine. when I looked at the conversion to Word  docx I
    found it had been transformed into 83MB.
    So the conversion (which was a children's book with lots of images in it) 
    resulted in an increase of MBs by a factor of 1.7.  
    The second pdf document I uploaded was 64MB and this failed. If I apply the
    1.7 factor then the Word docx I wanted was going to be 109MB and therefore
    over  the 100MB limit.
    I didn't know that converting pdf to word would increase the MB like that. 
    Why, I don't know so thanks for your help I've learnt something new.
    Cheers
                Garth
    In a message dated 07/10/2013 04:42:36 GMT Daylight Time, 
    [email protected] writes:
    Re:  Help needed using adobe exportpdf
    created by StacySison (http://forums.adobe.com/people/StacySison)  in 
    Adobe ExportPDF - View the full  discussion
    (http://forums.adobe.com/message/5740689#5740689)

  • Recursive subquery factoring datatypes?

    Hi all,
    using 11.2.0.2.0
    just mucking around with Recursive Subquery Factoring, trying to get my head around it.
    I can do this fine:
    SQL> with numlist (num) AS (SELECT 1 num
      2                          from dual
      3                          UNION ALL
      4                          SELECT numlist.num + 1
      5                            FROM numlist
      6                          where numlist.num < 10)
      7  SELECT *
      8    from numlist;
           NUM
             1
             2
             3
             4
             5
             6
             7
             8
             9
            10
    10 rows selected.but not with dates:
    SQL> WITH datelist (dte) AS (SELECT to_date('01-01-2011','dd-mm-yyyy') Dte
      2                   FROM dual
      3                 UNION ALL
      4                 SELECT datelist.dte + 1
      5                   FROM datelist
      6                  WHERE datelist.dte < trunc(SYSDATE))
      7  select *
      8    from datelist;
                   SELECT datelist.dte + 1
    ERROR at line 4:
    ORA-01790: expression must have same datatype as corresponding expressionI'm not sure what I need to do.....
    I'm sure it's a fairly straightforward

    Hemant K Chitale wrote:
    I don't have an 11.2.0 environment to test this.
    Try with a CAST at line 4 ? CAST X.DTE to a Date ?
    Hemant K Chitaleahh, that's a little bit better.... it seems a little bit funky though:
    15:38:58 SQL> WITH x (dte) AS (SELECT cast (to_date('01-01-2011','dd-mm-yyyy') as date) Dte
    15:39:02   2                   FROM dual
    15:39:02   3                 UNION ALL
    15:39:02   4                 SELECT cast(x.dte + 1 as date)
    15:39:02   5                   FROM x
    15:39:02   6                  WHERE x.dte < to_date('01-02-2011','dd-mm-yyyy'))
    15:39:02   7  select *
    15:39:02   8    from x;
    DTE
    01-JAN-11
    31-DEC-10
    30-DEC-10
    29-DEC-10
    28-DEC-10
    27-DEC-10
    26-DEC-10
    25-DEC-10
    24-DEC-10
    23-DEC-10
    22-DEC-10
    21-DEC-10
    20-DEC-10
    19-DEC-10
    18-DEC-10
    17-DEC-10
    16-DEC-10
    15-DEC-10
    14-DEC-10
    13-DEC-10
    12-DEC-10
    11-DEC-10
    10-DEC-10
    09-DEC-10
    08-DEC-10
    07-DEC-10
    06-DEC-10
    05-DEC-10
    04-DEC-10
    03-DEC-10
    02-DEC-10
    01-DEC-10
    30-NOV-10
    29-NOV-10
    28-NOV-10
    27-NOV-10
    26-NOV-10
    25-NOV-10
    24-NOV-10
    23-NOV-10
    22-NOV-10
    21-NOV-10
    20-NOV-10
    ...looks like it's going backwards.
    if I cast it like the below, it only gives me one record...
    15:39:03 SQL> WITH x (dte) AS (SELECT cast (to_date('01-01-2011','dd-mm-yyyy') as date) Dte
    15:40:52   2                   FROM dual
    15:40:52   3                 UNION ALL
    15:40:52   4                 SELECT cast(x.dte as date) + 1
    15:40:52   5                   FROM x
    15:40:52   6                  WHERE x.dte < to_date('01-02-2011','dd-mm-yyyy'))
    15:40:52   7  select *
    15:40:52   8    from x;
    DTE
    01-JAN-11
    1 row selected.This is bizarre....

  • When does OBIEE forcibly use Subquery Factoring ?

    In a 10.2 "datawarehouse" schema I see OBIEE queries of the form :
    WITH  SAWITH0 AS (select distinct T12345.COLUMN_1 as c1 from       DIMENSION_TABLE T12345
                      where  ( T12345.COLUMN_1 like 'HEMANT%')
    ) select distinct SAWITH0.c1 as c1 from       SAWITH0I cannot understand why OBIEE wouldn't run a simpler
    select distinct T12345.COLUMN_1 as c1 from       DIMENSION_TABLE T12345
    where  ( T12345.COLUMN_1 like 'HEMANT%')What OBIEE setup would cause even simple queries to be generated as using Subquery Factoring ?
    Hemant K Chitale
    http://hemantoracledba.blogspot.com

    Hi Hemant,
    use of WITH can be disabled in the OBIEE RPD Connection pool. Its enabled by default to allow the performance benefit you would see when using aggregated result sets. I personally think the OBIEE server is simply not advanced enough to determine when it doesn't need to use it (ie when selecting distinct dimension member values in dashboard prompts).
    Just my 2c. Hopefully some of the experianced users on here can expand a little more for you. Id be interested to know as well.

  • Troubleshoting help needed:  My iMac keeps crashing and restarting with a report detail: "spinlock application timed out"  What can I do to fix this?timed out"

    Troubleshooting help needed:  My iMac keeps crashing and restarting with a notice: "Spinlock application timed out"  What can I do?

    Launch the Console application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Console in the page that opens.
    Select the most recent panic log under System Diagnostic Reports. Post the contents — the text, please, not a screenshot. In the interest of privacy, I suggest you edit out the “Anonymous UUID,” a long string of letters, numbers, and dashes in the header and body of the report, if it’s present (it may not be.) Please don't post shutdownStall, spin, or hang reports.

  • Help needed for writing query

    help needed for writing query
    i have the following tables(with data) as mentioned below
    FK*-foregin key (SUBJECTS)
    FK**-foregin key (COMBINATION)
    1)SUBJECTS(table name)     
    SUB_ID(NUMBER) SUB_CODE(VARCHAR2) SUB_NAME (VARCHAR2)
    2           02           Computer Science
    3           03           Physics
    4           04           Chemistry
    5           05           Mathematics
    7           07           Commerce
    8           08           Computer Applications
    9           09           Biology
    2)COMBINATION
    COMB_ID(NUMBER) COMB_NAME(VARCHAR2) SUB_ID1(NUMBER(FK*)) SUB_ID2(NUMBER(FK*)) SUB_ID3(NUMBER(FK*)) SUBJ_ID4(NUMBER(FK*))
    383           S1      9           4           2           3
    384           S2      4           2           5           3
    ---------I actually designed the ABOVE table also like this
    3) a)COMBINATION
    COMB_ID(NUMBER) COMB_NAME(VARCHAR2)
    383           S1
    384           S2
    b)COMBINATION_DET
    COMBDET_ID(NUMBER) COMB_ID(FK**) SUB_ID(FK*)
    1               383          9
    2               383          4
    3               383          2
    4               383          3
    5               384          4
    6               384          2          
    7               384          5
    8               384          3
    Business rule: a combination consists of a maximum of 4 subjects (must contain)
    and the user is less relevant to a COMB_NAME(name of combinations) but user need
    the subjects contained in combinations
    i need the following output
    COMB_ID COMB_NAME SUBJECT1 SUBJECT2      SUBJECT3      SUBJECT4
    383     S1     Biology Chemistry      Computer Science Physics
    384     S2     Chemistry Computer Science Mathematics Physics
    or even this is enough(what i actually needed)
    COMB_ID     subjects
    383           Biology,Chemistry,Computer Science,Physics
    384           Chemistry,Computer Science,Mathematics,Physics
    you can use any of the COMBINATION table(either (2) or (3))
    and i want to know
    1)which design is good in this case
    (i think SUB_ID1,SUB_ID2,SUB_ID3,SUB_ID4 is not a
    good method to link with same table but if 4 subjects only(and must) comes
    detail table is not neccessary )
    now i am achieving the result by program-coding in C# after getting the rows from oracle
    i am using oracle 9i (also ODP.NET)
    i want to know how can i get the result in the stored procedure itsef.
    2)how it could be designed in any other way.
    any help/suggestion is welcome
    thanks for your time --Pradeesh

    Well I forgot the table-alias, here now with:
    SELECT C.COMB_ID
    , C.COMB_NAME
    , (SELECT SUB_NAME
    FROM SUBJECTS
    WHERE SUB_ID = C.SUB_ID1) AS SUBJECT_NAME1
    , (SELECT SUB_NAME
    FROM SUBJECTS
    WHERE SUB_ID = C.SUB_ID2) AS SUBJECT_NAME2
    , (SELECT SUB_NAME
    FROM SUBJECTS
    WHERE SUB_ID = C.SUB_ID3) AS SUBJECT_NAME3
    , (SELECT SUB_NAME
    FROM SUBJECTS
    WHERE SUB_ID = C.SUB_ID4) AS SUBJECT_NAME4
    FROM COMBINATION C;
    As you need exactly 4 subjects, the columns-solution is just fine I would say.

  • Help needed I have a canon 40D. I am thinking of buying a canon 6D.But not sure that my len

    Hi all help needed I have a canon 40D. I am thinking of buying a canon 6D.
    But not sure that my lenses will work.
    I have a 170mm/ 500mm APO Sigma.
    A 10/20 ex  Sigma   HSM  IF.
    And a 180 APO Sigma Macro or do I have to scrap them and buy others.
    ALL Help will be greatly received. Yours  BRODIE

    In short, I love it. I was going to buy the 5DMark III. After playing with it for a while at my local Fry's store where they put 5DMII, 5DMIII and 6D next to each other, using the same 24-105L lens, I decided to get the 6D and pocket the different for lens later.
    I'm upgrading from the 30D. So I think you'll love it. It's a great camera. I have used 5DMII extensively before (borrowing from a close friend).
    Funny thing is at first I don't really care about the GPS and Wifi much. I thought they're just marketing-gimmick. But once you have it, it is actually really fun and helpful. For example, I can place the 6D on a long "monopod", then use the app on the phone to control the camera to get some unique perspective on some scenes. It's fun and great. GPS is also nice for travel guy like me.
    Weekend Travelers Blog | Eastern Sierra Fall Color Guide

  • Help needed! Raid degraded again!

    Hi!
    Help needed! I hava made bootable RAID with two S-ATAII 250Gb HDD and its not working! Every now and then at bootup I get a message RAID -> DEGRADED... Must be seventh time! Rebuild takes its own time!
    What am I doing wrong!
    T: Ekku
    K8N Neo4 Ultra
    AMD 64 4200+
    2 Gb RAM
    2 x 250 Gb HDD (Maxtor)
    nVidia RAID (in mb)
    P.S. I wery SORRY with my poor language!

    I'm going to blame the nVRAID because I've seen issues with it in the past. If your motherboard has another non-nVidia RAID solution, use that instead. Using the nVidia SATA ports as BASE or JBOD is fine and dandy but RAIDing always had issues. It's not even a driver issue I think it's just instability. Latest drivers and even boxed drivers never helped. Granted, some will report success with their rig. But on a professional level I've seen nForce issues on different motherboards and different hard drives that had RAID disaster stories.
    Good luck and if you don't have another RAID solution, my suggestion would be to buy a dedicated RAID controller card.
    LPB

  • HELP NEEDED WITH ADDAPTER-DVI TO VGA.

    PLEASE ...HELP NEEDED WITH WIRING CROSS OVER....CAN YOU HELP WITH BACK OF PLUG CONNECTIONS...I SORTA UNDERSTAND THE PINOUTS BUT CANT MAKE AN EXACT MACH...WOULD LIKE TO BE 100% SURE...
    ......THIS ENSURES NO SMOKE!!!                                                                                           
    THE CARD IS AN ATI RADEON RX9250-DUAL HEAD-.........ADDAPTER IS DVI(ANALOG)MALE TO VGA(ANALOG)FEMALE.
    ANY HELP VERY MUCH APPRECIATED........ SEEMS YOU NEED TO BE ROCKET SCI TO ATTACH A BLOODY PICTURE...SO THIS HAS BEEN BIG WASTE OF FING TIME!

    Quote from: BOBHIGH on 17-December-05, 09:21:31
    Get over it mate !
    I find it easy t read CAPS...and if you dont like it ...DONT READ IT!
    And why bother to reply...some people have nothing better to do.
    Yes there chep and easy to come by...Ive already got a new one.
    All I wanted was to make a diagram of whats inside the bloody thing...it was a simple question and required a simple answer.
    NO NEED TO A WANKA !!
    I feel a bann comming up.
    Have you tryed Google ? really.. your question is inrelevant. No need to reply indeed.
    Why do you come here asking this question anyway ? is it becouse you have a MSI gfx card ? and the adapter has nothing to do with this ?
    You think you can come in here yelling.. thinking we have to put up with it and accept your style of posting. This is not a MSI tech center.. it's a user to user center.. Your question has nothing to do with MSI relavant things anyway's.
    Google = your friend.
    Quote from: BOBHIGH on 17-December-05, 09:21:31
    it was a simple question and required a simple answer
    Simple for who ? you (buying a new one) ? me ? we ?   .really...........
    Quote from: Dynamike on 16-December-05, 04:11:48
    1: There are allot of diffrent types of those adapters.
    If any of the mods have a problem about my reply.. please pm me.

  • Help needed for grouping.

    Hi,
        Help needed .
    I have an internal table having 6 .
    Ex :
    f1     f2    f3     f4    f5    f6
    a     aa    11    p1  10    10
    a     aa    12    p1  20    20
    b     aa    11    p2  30    30
    b     aa    12    p2  40    30
    Now i want to sum the fields f5 and f6 individually and need to display based upon the fields f1 and f4.
    To Display :
    f1     f2    f3     f4    f5    f6
    a     aa    11    p1  30    30.
    b     aa    11    p2  70    60.
    can anyone help me.How to do this..?
    Thanks

    Here you go
    DATA:
      BEGIN OF cur_tab OCCURS 0,
        f1        TYPE c,
        f2(2)     TYPE c,
        f3(2)     TYPE c,
        f4(2)     TYPE c,
        f5(2)     TYPE c,
        f6(2)     TYPE n,
      END OF cur_tab.
    DATA:
      BEGIN OF sum_tab OCCURS 0,
        f1        TYPE c,
        f4(2)     TYPE c,
        f5        TYPE p,
        f6        TYPE p,
      END OF sum_tab.
    DATA:
      BEGIN OF final_tab OCCURS 0,
        f1        TYPE c,
        f2(2)     TYPE c,
        f3(2)     TYPE c,
        f4(2)     TYPE c,
        f5(5)     TYPE c,
        f6(5)     TYPE c,
      END OF final_tab.
    START-OF-SELECTION.
      cur_tab-f1 = 'a'.
      cur_tab-f2 = 'aa'.
      cur_tab-f3 = '11'.
      cur_tab-f4 = 'p1'.
      cur_tab-f5 = '10'.
      cur_tab-f6 = '10'.
      APPEND cur_tab.
      cur_tab-f1 = 'a'.
      cur_tab-f2 = 'aa'.
      cur_tab-f3 = '11'.
      cur_tab-f4 = 'p1'.
      cur_tab-f5 = '20'.
      cur_tab-f6 = '20'.
      APPEND cur_tab.
      cur_tab-f1 = 'b'.
      cur_tab-f2 = 'aa'.
      cur_tab-f3 = '11'.
      cur_tab-f4 = 'p2'.
      cur_tab-f5 = '30'.
      cur_tab-f6 = '30'.
      APPEND cur_tab.
      cur_tab-f1 = 'b'.
      cur_tab-f2 = 'aa'.
      cur_tab-f3 = '11'.
      cur_tab-f4 = 'p2'.
      cur_tab-f5 = '40'.
      cur_tab-f6 = '30'.
      APPEND cur_tab.
      LOOP AT cur_tab.
        MOVE-CORRESPONDING cur_tab TO sum_tab.
        COLLECT sum_tab.
      ENDLOOP.
      LOOP AT sum_tab.
        READ TABLE cur_tab WITH KEY f1 = sum_tab-f1
                                    f4 = sum_tab-f4.
        IF sy-subrc NE 0.
          WRITE:/ 'Something went very wrong'.
          CONTINUE.
        ENDIF.
        MOVE-CORRESPONDING cur_tab TO final_tab.
        MOVE-CORRESPONDING sum_tab TO final_tab.
        APPEND final_tab.
      ENDLOOP.
      LOOP AT final_tab.
        WRITE:/1 final_tab-f1,
              AT 5 final_tab-f2,
              AT 10 final_tab-f3,
              AT 15 final_tab-f4,
              AT 20 final_tab-f5,
              AT 25 final_tab-f6.
      ENDLOOP.
    and the output
    a   aa   11   p1     30   30  
    b   aa   11   p2     70   60  

  • Help needed on installation of Oracle 9i on Sun Solaris 8

    Hey,
    Help needed on installation of Oracle 9i EE on Sun Solaris 8. The problem I met was: we followed the installation guide from the documentation. And we selected the choice "install software only". After it was done successfully, we run Database Configuration Assistant utility to create a database instance. But finally it always tried to create the instance at the root directory ( / ) which doesn't have enough space and then failed. The case was that we have set the enviroment parameters: $ORACLE_BASE = /export/mydata, $ORACLE_HOME = /export/apps/oracle9i. That means it should be installed at /export/mydata, but it didn't. Any help or advice are welcome. Thanks.
    Simon

    I have downloaded Oracle 11G R2 version from Windows and extracted it in Windows and copied it into DVD after extraction in two folders. Now I am mounting that DVD in Solaris 10 installed in my VMware . I made a new directory named as 'installation ' under /export/home/oracle and copied the folders from DVD to 'installation' folder. Now I am entering installation folder and try to do ./runInstaller as 'oracle ' user and getting the error mentioned before.
    Edited by: 916438 on Mar 31, 2012 5:55 PM

  • Help needed on installation of Oracle 9i EE on Sun Solaris 8

    Hey,
    Help needed on installation of Oracle 9i EE on Sun Solaris 8. The problem I met was: we followed the installation guide from the documentation. And we selected the choice "install software only". After it was done successfully, we run Database Configuration Assistant utility to create a database instance. But finally it always tried to create the instance at the root directory ( / ) which doesn't have enough space and then failed. The case was that we have set the enviroment parameters: $ORACLE_BASE = /export/mydata, $ORACLE_HOME = /export/apps/oracle9i. That means it should be installed at /export/mydata, but it didn't. Any help or advice are welcome. Thanks.
    Simon

    I have downloaded Oracle 11G R2 version from Windows and extracted it in Windows and copied it into DVD after extraction in two folders. Now I am mounting that DVD in Solaris 10 installed in my VMware . I made a new directory named as 'installation ' under /export/home/oracle and copied the folders from DVD to 'installation' folder. Now I am entering installation folder and try to do ./runInstaller as 'oracle ' user and getting the error mentioned before.
    Edited by: 916438 on Mar 31, 2012 5:55 PM

  • Help needed in Finding Download location for Sun One Portal 7

    Hi,
    help needed for finding download location for Sun ONE Portal 7. I tried to find in Oracle Download page ,
    http://www.oracle.com/us/sun/sun-products-map-075562.html, But unable to find.
    Please share the link for download location.
    I am totally new in Sun ONE Portal.
    Thanks,
    Edited by: 945439 on Oct 5, 2012 3:41 AM

    try edelivery.oracle.com under sun products.

Maybe you are looking for

  • Evaluation of an ERP System

    Hi All, W.R.T. to following tangible benefits from an ERP systems, in your opinion what should be the way to evaluate the current legacy or Erp and prove the advantages of SAP over it. Empirical or Tangible Benefits from ERP System 1>Inventory Reduct

  • Bi Server Connection Refused

    Hi, i've installed BI Server EE on a virtual machine. I press "Start OC4J" and the batch file starts as i think. When i try to start "BI publisher" i see a Java Exception "Connection Refused" Some idea?

  • Using Business Catalyst

    My boss has heard about Business Catalyst and has asked me to research and try to implement a viable dynamic solution other than Joomla, Wordpress ect. I have also checked out Cushy CMS  by there is much more funtionallity in BC. I just wnat to know

  • Disconnecting in PL/SQL

    Greetings All: I am writing a multithreaded embedded PL/SQL application in Visual C++ 6.0. The application registers as a 'listener' for a dbms_alert from a remote database. It waits for alerts using the waitone(...) method. The problem that I am hav

  • I'm getting Constant "Not Responding " and "Script Error"

    For a while now I have been getting a "Mozilla Firefox Not Responding " message and Firefox will slow down and keep not working, I'll also get a "Script Error" pop up box that keep reappearing around when the "Not Responding" messages happen. I have