WHERE clauses and Merge Join Cartesian?

For some reason, Siebel is generating queries like this:
                    AND CONCAT (CONCAT (t41828.lvl8anc_postn, '-'),
                                t41828.lvl8_emp_full_name
                               ) = 'GEO-SMITH, BILL'
                    AND CONCAT (CONCAT (t41828.lvl6anc_postn, '-'),
                                t41828.lvl6_emp_full_name
                               ) = 'GROUP1-DOE, JOHN'and this ends up with 3 merge join cartesian in autotrace and this query takes several hours.
However, by rewriting just those 2 clauses to:
                    AND (t41828.lvl8anc_postn = 'GEO' and
                                t41828.lvl8_emp_full_name = 'SMITH, BILL')
                    AND (t41828.lvl6anc_postn = 'GROUP1' and
                                t41828.lvl6_emp_full_name = 'DOE, JOHN')the merge join cartesians go away, and it runs in 7 seconds.
However, since Siebel is generating the query, and we are having issues, we decided to add columns for testing that is equivalent to the concatenation of the two columns above. After doing this, and creating indexes on the new columns, it is now back to the merge join cartesian and I cannot get rid of it.
So:
1. How can rewriting the WHERE (not adding or deleting anything here, just rewriting it in a different way) clause eliminate the merge join cartesian?
I'm guessing by understanding that single question, I will be able to come up with a better solution to this.

Note we made two additional columns:
CONCAT (CONCAT (t41828.lvl8anc_postn, '-'), t41828.lvl8_emp_full_name) => col1 CONCAT (CONCAT (t41828.lvl6anc_postn, '-'), t41828.lvl6_emp_full_name) => col2
When I created indexes on col1 and col2 and used them in the query, the cartesians returned, and I cannot figure out why. So, I'm still confused why:
In the original query:
1. Using CONCAT, and thus no indexes => cartesian
2. No CONCAT, and indexes => no cartesian
With the new columns, col1 and col2:
1. No CONCAT needed, full table scan or indexes => cartesian

Similar Messages

  • MERGE JOIN CARTESIAN

    Hi,
    I have a query which is using MERGE JOIN CARTESIAN (see step 4 and 11 in execution plan bellow) and i believe this is the culprit and query is never returning. Stats are up to date on all tables. This query involves two remote databases which are accessed using VIEWs from local database. Is there any hint which i can use here to avoid merge join Cartesian and test. Thanks. Also pasting query if any one can have any idea.
        Select  distinct
         substr(Revenue.FKDAT,5,2) || '/' || substr(Revenue.FKDAT,7,2) || '/' || substr(Revenue.FKDAT,1,4) INVOICE_DATE
        , Revenue.VBELN INVOICE_NR
        , Revenue.ARKTX CUSTDEVICE
        , (case Revenue.ZU_LOTID
        when null then hstg_partinfo_cust_dw.CUSTPARTOUT
        when '' then hstg_partinfo_cust_dw.CUSTPARTOUT
        Else
        (case decode(trim(zodss1b2.biztype),'TNR-E330-BAKE','TNR','')
        when 'TNR' then
        (case when (select CUSTPARTOUT from hstg_partinfo_cust_dw Where lotid = 'U' || substr(Revenue.ZU_LOTID,2,7) || '.' || substr(Revenue.ZU_LOTID,9) and stage = 'T998-TFIN' and rownum = 1)
         is null then (select CUSTPARTOUT from hstg_partinfo_cust_dw Where lotid = (select parentid from hstg_partinfo_cust_dw where lotid = 'U' || substr(Revenue.ZU_LOTID,2,7) || '.' || substr(Revenue.ZU_LOTID,9) and stage = 'E330-BAKE' and rownum = 1) and stage = 'T998-TFIN' and rownum = 1)
        else (select CUSTPARTOUT from hstg_partinfo_cust_dw Where lotid = 'U' || substr(Revenue.ZU_LOTID,2,7) || '.' || substr(Revenue.ZU_LOTID,9) and stage = 'T998-TFIN' and rownum = 1)
        end)
        else hstg_partinfo_cust_dw.CUSTPARTOUT
        end)
        end) CUSTPARTOUT
        , Revenue.PONUM DO_NR
        , Revenue.BSTKD PO_NR
        , Revenue.FKIMG GD_QTY
        , Revenue.zkbetr GD_PRICE
        , Revenue.NETWR GD_AMT
        , '' REJ_QTY
        , '' REJ_PRICE
        , '' REJ_AMT
        , Revenue.ZU_LOTID LOTTYPE
        ,(case Revenue.ZU_LOTID
        when null then substr(Revenue.ZU_PRTID,1,instr(Revenue.ZU_PRTID,'.') -1)
        when '' then substr(Revenue.ZU_PRTID,1,instr(Revenue.ZU_PRTID,'.') -1)
        Else
        (case decode(trim(zodss1b2.biztype),'TNR-E330-BAKE','TNR','')
        when 'TNR' then
       (case when (select substr(PARTID,1,instr(PARTID,'.') -1) from hstg_partinfo_cust_dw Where lotid = 'U' || substr(Revenue.ZU_LOTID,2,7) || '.' || substr(Revenue.ZU_LOTID,9) and stage = 'T998-TFIN' and  rownum = 1)
         is null then (select substr(PARTID,1,instr(PARTID,'.') -1) from hstg_partinfo_cust_dw Where lotid = (select parentid from hstg_partinfo_cust_dw where lotid = 'U' || substr(Revenue.ZU_LOTID,2,7) || '.' || substr(Revenue.ZU_LOTID,9) and stage = 'E330-BAKE' and rownum = 1) and stage = 'T998-TFIN' and rownum = 1)
        else (select substr(PARTID,1,instr(PARTID,'.') -1) from hstg_partinfo_cust_dw Where lotid = 'U' || substr(Revenue.ZU_LOTID,2,7) || '.' || substr(Revenue.ZU_LOTID,9) and stage = 'T998-TFIN' and rownum = 1)
        end)
        else substr(Revenue.ZU_PRTID,1,instr(Revenue.ZU_PRTID,'.') -1)
        end)
        end) PARTID
        , '' TESTER
        , substr(zodss1b2.BSTDK,5,2) || '/' || substr(zodss1b2.BSTDK,7,2) || '/' || substr(zodss1b2.BSTDK,1,4) DO_DATE
        , hstg_partinfo_cust_dw.package package
        , hstg_partinfo_cust_dw.pincount pincount
        , (select c.catg07 from ops$ods_adm.catg c where c.partid=revenue.zu_prtid) as package_size
        , (select c.catg09 from ops$ods_adm.catg c where c.partid=revenue.zu_prtid) as wafer_size
        , decode(trim(zodss1b2.biztype),'TNR-E330-BAKE','TNR','') BIZTYPE
         --from revenue, zodss1b2,dim_partinfo
         from revenue, zodss1b2,hstg_partinfo_cust_dw
         where Revenue.Remarks <> 'CANCELLED'
         and Revenue.FKART in ('ZUF2')
         and Revenue.KUNNR in ('BC1001','BC1002','BC1003')
         and Revenue.FKDAT like '201008%'
         and Revenue.FKIMG > 0
         and Revenue.kpein > 0
         and Revenue.ZU_LOTID = zodss1b2.charg
         and Revenue.MATNR = zodss1b2.matnr
         --and Revenue.ZU_PRTID = dim_partinfo.partid
         and hstg_partinfo_cust_dw.lotid='U' || substr(Revenue.ZU_LOTID,2,7) || '.' || substr(Revenue.ZU_LOTID,9)
        Union all
         Select distinct
         substr(Revenue.FKDAT,5,2) || '/' || substr(Revenue.FKDAT,7,2) || '/' || substr(Revenue.FKDAT,1,4) INVOICE_DATE
        , Revenue.VBELN INVOICE_NR
        , Revenue.ARKTX CUSTDEVICE
        , hstg_partinfo_cust_dw.CUSTPARTOUT CUSTPARTOUT
        , Revenue.PONUM DO_NR
        , Revenue.BSTKD PO_NR
        , Revenue.FKIMG GD_QTY
        , Revenue.zkbetr GD_PRICE
        , Revenue.NETWR GD_AMT
        , '' REJ_QTY
        , '' REJ_PRICE
        , '' REJ_AMT
        , Revenue.ZU_LOTID LOTTYPE
        , substr(Revenue.ZU_PRTID,1,instr(Revenue.ZU_PRTID,'.') -1) PARTID
        , '' TESTER
        , substr(zodsscrap.BSTDK,5,2) || '/' || substr(zodsscrap.BSTDK,7,2) || '/' || substr(zodsscrap.BSTDK,1,4) DO_DATE
        , hstg_partinfo_cust_dw.package package
        , hstg_partinfo_cust_dw.pincount pincount
        , (select c.catg07 from ops$ods_adm.catg c where c.partid=revenue.zu_prtid) as package_size
        , (select c.catg09 from ops$ods_adm.catg c where c.partid=revenue.zu_prtid) as wafer_size
         --from revenue, zodsscrap,dim_partinfo
         from revenue, zodsscrap,hstg_partinfo_cust_dw
         where Revenue.Remarks <> 'CANCELLED'
         and Revenue.FKART in ('ZUF2')
         and Revenue.KUNNR in ('BC1001','BC1002','BC1003')
         and Revenue.FKDAT like '201008%'
         and Revenue.FKIMG > 0
         and Revenue.kpein > 0
         and Revenue.ZU_LOTID = zodsscrap.charg
         --and Revenue.ZU_PRTID = dim_partinfo.partid
         and hstg_partinfo_cust_dw.lotid='U' || substr(Revenue.ZU_LOTID,2,7) || '.' || substr(Revenue.ZU_LOTID,9);hstg_partinfo_cust_dw is a view which is on remote database USGDWDBP and is queried using synonym in the local database.
    revenue is also a view which is in another remote database which is queried using synonym in local database.
    ODS Plan
    | Id  | Operation               |  Name       | Rows  | Bytes | Cost  | Inst   |IN-OUT|
    |   0 | SELECT STATEMENT        |             |     2 |  8532 |   999 |        |      |
    |   1 |  UNION-ALL              |             |       |       |       |        |      |
    |   2 |   SORT UNIQUE           |             |     1 |  4277 |   985 |        |      |
    |   3 |    NESTED LOOPS         |             |     1 |  4277 |   983 |        |      |
    |   4 |     MERGE JOIN CARTESIAN|             |     1 |  4107 |   980 |        |      |
    |   5 |      REMOTE             |             |     1 |  4076 |     2 | USGDW~ | R->S |
    |   6 |      BUFFER SORT        |             |   918K|    27M|   978 |        |      |
    |   7 |       TABLE ACCESS FULL | ZODSS1B2    |   918K|    27M|   978 |        |      |
    |   8 |     REMOTE              |             |     1 |   170 |     3 | SAPP0~ | R->S |
    |   9 |   SORT UNIQUE           |             |     1 |  4255 |    14 |        |      |
    |  10 |    NESTED LOOPS         |             |     1 |  4255 |    12 |        |      |
    |  11 |     MERGE JOIN CARTESIAN|             |     1 |  4096 |     9 |        |      |
    |  12 |      REMOTE             |             |     1 |  4076 |     2 | USGDW~ | R->S |
    |  13 |      BUFFER SORT        |             |  1755 | 35100 |     7 |        |      |
    |  14 |       TABLE ACCESS FULL | ZODSSCRAP   |  1755 | 35100 |     7 |        |      |
    |  15 |     REMOTE              |             |     1 |   159 |     3 | SAPP0~ | R->S |
    ---------------------------------------------------------------------------------------Thanks in advance
    Salman

    Dear Salman Qureshi,
    First of all please see Jonathan Lewis' post about the merge join cartesian;
    http://jonathanlewis.wordpress.com/2006/12/13/cartesian-merge-join/
    You may also check the Thomas Kyte's thread;
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:4105951726381
    You merge join cartesian cost is so low that the impact will not be that high.
    Yes, there are ways to avoid the merge join cartesian. First you have to check the where conditions. Merge join cartesian steps are happening because of the bad SQL algorithm OR sometimes Oracle needs to have a merge join cartesian. At the end, it is up to your SQL.
    After than that, you can also use the ORDERED CBO hint to avoid the merge join cartesian.
    Please add below line after the SELECT clause and see the new execution plan;
    /*+ ORDERED */I hope your problem will be fixed when you show the CBO to use the ORDERED Oracle hint.
    About the ORDERED Oracle hint, please check it out;
    http://download.oracle.com/docs/cd/B14117_01/server.101/b10752/hintsref.htm#5555
    ORDERED
    The ORDERED hint causes Oracle to join tables in the order in which they appear in the FROM clause.
    If you omit the ORDERED hint from a SQL statement performing a join, then the optimizer chooses the order in which to join the tables. You might want to use the ORDERED hint to specify a join order if you know something about the number of rows selected from each table that the optimizer does not. Such information lets you choose an inner and outer table better than the optimizer could.Hope That Helps.
    Ogan

  • Group by causing merge join cartesian?

    Hi All,
    Database Version: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
    Database Version: PL/SQL Release 10.2.0.5.0 - ProductionI've written a query which runs in under a second and produces a few hundred rows (as you can see below). I only wanted to find the number of distinct incident ID's returned so I put a group by at the end and it ran for ever.
    I produced an explain plan (as shown below) for the query with the group by in it and it is trying to perform a cartesian join!
    WTF is going on? I've never known a group by statement to do that before.
    basic structure of the tables is as follows:
    SQL> desc answer_master
    Name                                                                     Null?    Type
    ANSWER_ID                                                                NOT NULL NUMBER(12)
    INCIDENT_ID                                                              NOT NULL NUMBER(12)
    PLAN_ID                                                                  NOT NULL NUMBER(12)
    QUESTION_ID                                                              NOT NULL NUMBER(12)
    SQL> desc question_master
    Name                                                                     Null?    Type
    QUESTION_PLAN_ID                                                         NOT NULL NUMBER(12)
    QUESTION_ID                                                              NOT NULL NUMBER(12)
    QUESTION_TYPE                                                            NOT NULL NUMBER(2)
    QUESTION_TEXT                                                            NOT NULL VARCHAR2(255)
    QUESTION_PARENT_ID                                                                NUMBER(12)the offending SQL statement
    SQL> explain plan for
      2  select incident_id
      3    from answer_master am
      4   where exists (select 'x'
      5                   from answer_master am1
      6                  where question_id in (select question_id
      7                               from question_master qms
      8                              where question_plan_id = 1477
      9                                and question_parent_id = 69067
    10                                and substr(question_text,-3) = 'PDF')
    11                    and am1.incident_id = am.incident_id)
    12    and exists (select 'x'
    13                   from answer_master am1
    14                  where question_id in (select question_id
    15                               from question_master qms
    16                              where question_plan_id = 1477
    17                                and question_parent_id = 69067
    18                                and substr(question_text,-3) != 'PDF')
    19                    and am1.incident_id = am.incident_id);
    Explained.
    Elapsed: 00:00:00.01
    SQL> set linesize 132;
    SQL> select plan_table_output from table(dbms_xplan.display('plan_table',null,'serial'));
    PLAN_TABLE_OUTPUT                                                                                                                  
    Plan hash value: 1710257923                                                                                                        
    | Id  | Operation                        | Name                  | Rows  | Bytes | Cost (%CPU)| Time     |                         
    |   0 | SELECT STATEMENT                 |                       |     1 |    32 |   171   (6)| 00:00:01 |                         
    |*  1 |  HASH JOIN RIGHT SEMI            |                       |     1 |    32 |   171   (6)| 00:00:01 |                         
    |   2 |   VIEW                           | VW_SQ_2               |    71 |   923 |    70   (5)| 00:00:01 |                         
    |   3 |    NESTED LOOPS                  |                       |    71 |  3266 |    70   (5)| 00:00:01 |                         
    |*  4 |     TABLE ACCESS BY INDEX ROWID  | QUESTION_MASTER       |     1 |    35 |     2   (0)| 00:00:01 |                         
    |*  5 |      INDEX RANGE SCAN            | QUESTION_MASTER_IX1   |     3 |       |     1   (0)| 00:00:01 |                         
    |*  6 |     INDEX RANGE SCAN             | ANSWER_MASTER_QID_IX2 | 18731 |   201K|    68   (5)| 00:00:01 |                         
    |   7 |   NESTED LOOPS                   |                       |   304 |  5776 |   100   (5)| 00:00:01 |                         
    |   8 |    VIEW                          | VW_SQ_1               |    14 |   182 |    70   (5)| 00:00:01 |                         
    |   9 |     HASH UNIQUE                  |                       |    14 |   644 |            |          |                         
    |  10 |      NESTED LOOPS                |                       |    14 |   644 |    70   (5)| 00:00:01 |                         
    |* 11 |       TABLE ACCESS BY INDEX ROWID| QUESTION_MASTER       |     1 |    35 |     2   (0)| 00:00:01 |                         
    |* 12 |        INDEX RANGE SCAN          | QUESTION_MASTER_IX1   |     3 |       |     1   (0)| 00:00:01 |                         
    |* 13 |       INDEX RANGE SCAN           | ANSWER_MASTER_QID_IX2 | 18731 |   201K|    68   (5)| 00:00:01 |                         
    |* 14 |    INDEX RANGE SCAN              | ANSWER_MASTER_QID_IX3 |    22 |   132 |     2   (0)| 00:00:01 |                         
    Predicate Information (identified by operation id):                                                                                
       1 - access("ITEM_2"="AM"."INCIDENT_ID")                                                                                         
       4 - filter("QUESTION_PLAN_ID"=1477 AND SUBSTR("QUESTION_TEXT",-3)!='PDF')                                                       
       5 - access("QUESTION_PARENT_ID"=69067)                                                                                          
       6 - access("QUESTION_ID"="QUESTION_ID")                                                                                         
      11 - filter("QUESTION_PLAN_ID"=1477 AND SUBSTR("QUESTION_TEXT",-3)='PDF')                                                        
      12 - access("QUESTION_PARENT_ID"=69067)                                                                                          
      13 - access("QUESTION_ID"="QUESTION_ID")                                                                                         
      14 - access("ITEM_1"="AM"."INCIDENT_ID")                                                                                         
    33 rows selected.
    Elapsed: 00:00:00.06
    SQL> explain plan for
      2  select incident_id
      3    from answer_master am
      4   where exists (select 'x'
      5                   from answer_master am1
      6                  where question_id in (select question_id
      7                               from question_master qms
      8                              where question_plan_id = 1477
      9                                and question_parent_id = 69067
    10                                and substr(question_text,-3) = 'PDF')
    11                    and am1.incident_id = am.incident_id)
    12    and exists (select 'x'
    13                   from answer_master am1
    14                  where question_id in (select question_id
    15                               from question_master qms
    16                              where question_plan_id = 1477
    17                                and question_parent_id = 69067
    18                                and substr(question_text,-3) != 'PDF')
    19                    and am1.incident_id = am.incident_id)
    20  group by incident_id;
    Explained.
    Elapsed: 00:00:00.00
    SQL> select plan_table_output from table(dbms_xplan.display('plan_table',null,'serial'));
    PLAN_TABLE_OUTPUT                                                                                                                  
    Plan hash value: 1433543102                                                                                                        
    | Id  | Operation                         | Name                  | Rows  | Bytes | Cost (%CPU)| Time     |                        
    |   0 | SELECT STATEMENT                  |                       |     1 |    98 |    77   (6)| 00:00:01 |                        
    |   1 |  HASH GROUP BY                    |                       |     1 |    98 |    77   (6)| 00:00:01 |                        
    |   2 |   NESTED LOOPS                    |                       |     1 |    98 |    76   (4)| 00:00:01 |                        
    |   3 |    NESTED LOOPS                   |                       |     1 |    87 |    74   (5)| 00:00:01 |                        
    |   4 |     NESTED LOOPS                  |                       |     1 |    81 |    72   (5)| 00:00:01 |                        
    |   5 |      MERGE JOIN CARTESIAN         |                       |     1 |    70 |     4   (0)| 00:00:01 |                        
    |*  6 |       TABLE ACCESS BY INDEX ROWID | QUESTION_MASTER       |     1 |    35 |     2   (0)| 00:00:01 |                        
    |*  7 |        INDEX RANGE SCAN           | QUESTION_MASTER_IX1   |     3 |       |     1   (0)| 00:00:01 |                        
    |   8 |       BUFFER SORT                 |                       |     1 |    35 |     2   (0)| 00:00:01 |                        
    |*  9 |        TABLE ACCESS BY INDEX ROWID| QUESTION_MASTER       |     1 |    35 |     2   (0)| 00:00:01 |                        
    |* 10 |         INDEX RANGE SCAN          | QUESTION_MASTER_IX1   |     3 |       |     1   (0)| 00:00:01 |                        
    |* 11 |      INDEX RANGE SCAN             | ANSWER_MASTER_QID_IX2 | 18731 |   201K|    68   (5)| 00:00:01 |                        
    |* 12 |     INDEX RANGE SCAN              | ANSWER_MASTER_QID_IX3 |    22 |   132 |     2   (0)| 00:00:01 |                        
    |* 13 |    INDEX RANGE SCAN               | ANSWER_MASTER_QID_IX2 |     1 |    11 |     2   (0)| 00:00:01 |                        
    Predicate Information (identified by operation id):                                                                                
       6 - filter("QUESTION_PLAN_ID"=1477 AND SUBSTR("QUESTION_TEXT",-3)='PDF')                                                        
       7 - access("QUESTION_PARENT_ID"=69067)                                                                                          
       9 - filter("QUESTION_PLAN_ID"=1477 AND SUBSTR("QUESTION_TEXT",-3)!='PDF')                                                       
      10 - access("QUESTION_PARENT_ID"=69067)                                                                                          
      11 - access("QUESTION_ID"="QUESTION_ID")                                                                                         
      12 - access("AM1"."INCIDENT_ID"="AM"."INCIDENT_ID")                                                                              
      13 - access("QUESTION_ID"="QUESTION_ID" AND "AM1"."INCIDENT_ID"="AM"."INCIDENT_ID")                                              
    31 rows selected.
    Elapsed: 00:00:00.00
    SQL> spool offedit: changing greater-than/less-than signs to != so it displays on forum
    Edited by: WhiteHat on Feb 11, 2011 9:37 AM

    The "Cartesian" product is nothing "wrong", if (!) the optimizer is right and the number or rows it's picking for that part of the execution plan is really 1. And that can be true, as ORACLE also changed from HASH join to NL. So that NL might be the cause of your performance issue not the Cartesian.
    The performance of IN, EXISTS and SUBQUERIES got better over the versions, but I still see no reason in most cases to use them for good readable and performing code.
    What you do think about this:
    WITH my_selection As
    (SELECT incident_id
    from question_master qms
       where question_plan_id = 1477
       and question_parent_id = 69067
       and (substr(question_text,-3) = 'PDF'
            or and substr(question_text,-3) != 'PDF')
       GROUP BY incident_id
       HAVING COUNT(*) >1)
    SELECT am.incident_id
      FROM answer_master am
         INNER JOIN my_selection s
          ON am.incident_id = s.incident_id
    group by am.incident_id;

  • MERGE JOIN cartesian help

    Hi All,
    I have a problem in writing the below query. The below query always shows an MERGE JOIN CARTESIAN in the explain plan due to which the query execution takes lot of time(close to 2 hour for 1000 records).
    I'm using "Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi". Please advice if I need to provide more information on this.
    Select to_char(a.amnt_date,'DD-MON-YYYY') amnt_date,
           SUM(a.AMNT_CON) amount
    from amount a,
         (SELECT area_no 
             FROM (SELECT *
                      FROM area_usage
                      WHERE area_hier_no = '201064')
          CONNECT BY area_par_no = PRIOR area_no
          START WITH area_no in (SELECT area_no
                                    FROM area
                                    WHERE area_code in ('EQ'))) b,
         (SELECT acc_no
             FROM (SELECT *
                     FROM acc_usage
                    WHERE acc_hier_no = '1')
          CONNECT BY acc_par_no = PRIOR acc_no
          START WITH acc_no = 202917) c --  Account Hierarchy
    where a.area_no = b.area_no
       AND a.acc_no = c.acc_no
    GROUP BY a.amnt_date-----
    PLAN_TABLE_OUTPUT
    PLAN_TABLE_OUTPUT
    Plan hash value: 2492729134
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
    | 0 | SELECT STATEMENT | | 692 | 22144 | 3327 (32)| 00:00:40 | | |
    | 1 | HASH GROUP BY | | 692 | 22144 | 3327 (32)| 00:00:40 | | |
    | 2 | TABLE ACCESS BY LOCAL INDEX ROWID | AMOUNT | 138 | 2898 | 3326 (32)| 00:00:40 | | |
    | 3 | NESTED LOOPS | | 692 | 22144 | 3326 (32)| 00:00:40 | | |
    | 4 | MERGE JOIN CARTESIAN | | 5 | 55 | 13 (0)| 00:00:01 | | |
    | 5 | VIEW | | 1 | 5 | 5 (0)| 00:00:01 | | |
    |* 6 | CONNECT BY WITH FILTERING | | | | | | | |
    | 7 | TABLE ACCESS BY INDEX ROWID | ACC_USAGE | 1 | 24 | 2 (0)| 00:00:01 | | |
    |* 8 | INDEX UNIQUE SCAN | ACU_PK | 1 | | 1 (0)| 00:00:01 | | |
    | 9 | NESTED LOOPS | | | | | | | |
    | 10 | CONNECT BY PUMP | | | | | | | |
    |* 11 | TABLE ACCESS BY INDEX ROWID | ACC_USAGE | 1 | 14 | 5 (0)| 00:00:01 | | |
    |* 12 | INDEX RANGE SCAN | ACU_AH_HAVE_AS_PARENT_FK_I | 4 | | 1 (0)| 00:00:01 | | |
    | 13 | BUFFER SORT | | 5 | 30 | 13 (0)| 00:00:01 | | |
    | 14 | VIEW | | 5 | 30 | 8 (0)| 00:00:01 | | |
    |* 15 | CONNECT BY WITH FILTERING | | | | | | | |
    |* 16 | TABLE ACCESS BY INDEX ROWID | AREA_USAGE | | | | | | |
    | 17 | NESTED LOOPS | | 1 | 32 | 2 (0)| 00:00:01 | | |
    | 18 | TABLE ACCESS BY INDEX ROWID| AREA | 1 | 21 | 2 (0)| 00:00:01 | | |
    |* 19 | INDEX UNIQUE SCAN | AR_AR2_UK | 1 | | 1 (0)| 00:00:01 | | |
    |* 20 | INDEX UNIQUE SCAN | AU_PK | 8608 | 94688 | 0 (0)| 00:00:01 | | |
    | 21 | NESTED LOOPS | | | | | | | |
    | 22 | CONNECT BY PUMP | | | | | | | |
    |* 23 | TABLE ACCESS BY INDEX ROWID | AREA_USAGE | 5 | 85 | 8 (0)| 00:00:01 | | |
    |* 24 | INDEX RANGE SCAN | ARU_APN_FKI | 8 | | 1 (0)| 00:00:01 | | |
    | 25 | PARTITION RANGE ALL | | | | | | 1 | 60 |
    | 26 | BITMAP CONVERSION TO ROWIDS | | | | | | | |
    | 27 | BITMAP AND | | | | | | | |
    | 28 | BITMAP CONVERSION FROM ROWIDS | | | | | | | |
    |* 29 | INDEX RANGE SCAN | A_ARH_FK_I | 194K| | 134 (7)| 00:00:02 | 1 | 60 |
    | 30 | BITMAP CONVERSION FROM ROWIDS | | | | | | | |
    |* 31 | INDEX RANGE SCAN | A_AH_FK_I | 194K| | 488 (41)| 00:00:06 | 1 | 60 |
    Predicate Information (identified by operation id):
    6 - access("ACC_USAGE"."ACC_PAR_NO"=PRIOR "ACC_USAGE"."ACC_NO")
    8 - access("ACC_USAGE"."ACC_NO"=202917 AND "ACC_HIER_NO"=1)
    11 - filter("ACC_HIER_NO"=1)
    12 - access("ACC_USAGE"."ACC_PAR_NO"=PRIOR "ACC_USAGE"."ACC_NO")
    15 - access("AREA_USAGE"."AREA_PAR_NO"=PRIOR "AREA_USAGE"."AREA_NO")
    16 - filter("AREA_HIER_NO"=201064)
    19 - access("AREA_CODE"='EQ')
    20 - access("AREA_HIER_NO"=201064 AND "AREA_USAGE"."AREA_NO"="AREA_NO")
    23 - filter("AREA_HIER_NO"=201064)
    24 - access("AREA_USAGE"."AREA_PAR_NO"=PRIOR "AREA_USAGE"."AREA_NO")
    29 - access("A"."AREA_NO"="B"."AREA_NO")
    31 - access("A"."ACC_NO"="C"."ACC_NO")
    54 rows selected.
    Edited by: Harinath Arasu on Oct 14, 2010 5:31 AM

    That's a very small difference, and I wouldn't expect that to cause huge shifts in an execution plan. Either way to gather statistics you would use the DBMS_STATS package.
    By the way, your "formatted" execution plan isn't exactly readable in your post.
    Looking at your query a little more closely I do recommend you remove the SELECT * from the subqueries. Something like this may suffice:
    Select to_char(a.amnt_date,'DD-MON-YYYY') amnt_date,
           SUM(a.AMNT_CON) amount
    from amount a,
         (SELECT area_no 
             FROM (SELECT area_no
                        , area_par_no
                      FROM area_usage
                      WHERE area_hier_no = '201064')
          CONNECT BY area_par_no = PRIOR area_no
          START WITH area_no in (SELECT area_no
                                    FROM area
                                    WHERE area_code in ('EQ'))) b,
         (SELECT acc_no
             FROM (SELECT acc_no
                        , acc_par_no
                     FROM acc_usage
                    WHERE acc_hier_no = '1')
          CONNECT BY acc_par_no = PRIOR acc_no
          START WITH acc_no = 202917) c --  Account Hierarchy
    where a.area_no = b.area_no
       AND a.acc_no = c.acc_no
    GROUP BY a.amnt_dateUsing a SELECT * and not subsequently using all the columns is hiding valuable information from Oracle. If you provide only the columns used Oracle may be able to find a better execution plan.
    Granted I don't know the table structures so you could actually be using all the columns. I still recommend the change because I think it makes the code easier to understand.

  • Merge Join Cartesian in XML query

    Hi Sir
    I am getting Merge join cartesian in the below XML query
    SELECT
    x.empno,
    x1.empno AS INDEXempno
    FROM
    emp_vw x,
    emp_index x1,
    table (xmlsequence(extract(x1.xml_data,'/emp/org/constituent/'))) c
    WHERE x.empno = extractvalue(VALUE(c),'/constituent/code/text()');
    I am getting Merge join cartesian in XML query. whereeas below query i am running by I am not getting merge join cartesian
    SELECT
    x.empno,
    x1.empno AS INDEXempno
    FROM
    emp_vw_v6 x,
    emp_index_v6 x1,
    table (xmlsequence(extract(x1.xml_data,'/emp/org/constituent/'))) c
    WHERE x.empno = extractvalue(VALUE(c),'/constituent/code/text()');
    Here emp_vw is a view and emp_index is a table.This is not giving merge join cartesian
    However both the view and table are interdependent.
    Please help me to resolve the performance of the first query as it is taking a lot of time to execute.?
    Thanks & Regards
    Thakur Manoj R

    Please post a working test case, and follow the guidelines here : {message:id=9360002}
    What are the differences between the view and table in the first query and the two others (*_v6) in the second query?                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How can I pass multiple condition in where clause with the join table?

    Hi:
    I need to collect several inputs at run time, and query the record according to the input.
    How can I pass multiple conditions in where clause with the join table?
    Thanks in advance for any help.
    Regards,
    TD

    If you are using SQL-Plus or Reports you can use lexical parameters like:
    SELECT * FROM emp &condition;
    When you run the query it will ask for value of condition and you can enter what every you want. Here is a really fun query:
    SELECT &columns FROM &tables &condition;
    But if you are using Forms. Then you have to change the condition by SET_BLOCK_PROPERTY.
    Best of luck!

  • WHERE clause creating a join for two or more tables

    The CS3 Dreamweaver book says that the WHERE clause can
    create a join for two or more tables. The join was created, but the
    data is repeating. I have searched the web and this forum and have
    not found the answer.
    My Master page filters the recordset by Style No and when a
    customer clicks on a particular style, it sends him to the Detail
    page. All the records are showing from all tables on the detail
    page from the Dynamic List, except they are showing multiple times
    (ex. Size table has 4 sizes and Color table has 2 colors - my Size
    Drop Down list is showing 8 options and my Color Drop Down List is
    showing 8 options) I have a Master Page with a recordset pointing
    to a Detail Page using the same recordset.
    Master page works perfectly.
    Master Recordset SQL:
    SELECT products.itemID, products.category, products.styleno,
    products.name, products.description, products.ourprice,
    products.imageTH, products.image, coloroption.color,
    sizeoption.size
    FROM products, coloroption, sizeoption
    WHERE category = 'chefcoats' AND
    products.styleno=sizeoption.styleno AND
    products.styleno=coloroption.styleno
    GROUP BY products.styleno
    ORDER BY styleno ASC
    The Detail Recordset:
    SELECT products.itemID, products.category, products.styleno,
    products.name, products.description, products.ourprice,
    products.imageTH, products.image, sizeoption.size,
    coloroption.color
    FROM products, sizeoption, coloroption
    WHERE itemID=colname AND products.styleno=sizeoption.styleno
    AND products.styleno=coloroption.styleno
    I tried using the GROUP BY on the detail page, but then it
    only showed one size and color from the dynamic drop down list. I
    tried changing the field name "styleno" in the other tables to be
    unique, however, I was using the table identifer. I tried using the
    JOIN command instead of the WHERE clause and that didn't help
    either.
    On the detail page, the customer is supposed to click on the
    Size box and see sizes XSM - 6XL ONLY ONE TIME. and then be able to
    click on the Color option and see White, Black, Red ONE TIME.
    Is this possible?
    Thank you for giving your time to read this.!
    Evie

    Do you have a link we can look at to see what you are trying
    to do?
    Dave
    "EviePhillips" <[email protected]> wrote in
    message
    news:[email protected]...
    > The CS3 Dreamweaver book says that the WHERE clause can
    create a join for
    two
    > or more tables. The join was created, but the data is
    repeating. I have
    > searched the web and this forum and have not found the
    answer.
    >
    > My Master page filters the recordset by Style No and
    when a customer
    clicks on
    > a particular style, it sends him to the Detail page. All
    the records are
    > showing from all tables on the detail page from the
    Dynamic List, except
    they
    > are showing multiple times (ex. Size table has 4 sizes
    and Color table has
    2
    > colors - my Size Drop Down list is showing 8 options and
    my Color Drop
    Down
    > List is showing 8 options) I have a Master Page with a
    recordset pointing
    to a
    > Detail Page using the same recordset.
    >
    > Master page works perfectly.
    > Master Recordset SQL:
    > SELECT products.itemID, products.category,
    products.styleno,
    products.name,
    > products.description, products.ourprice,
    products.imageTH, products.image,
    > coloroption.color, sizeoption.size
    > FROM products, coloroption, sizeoption
    > WHERE category = 'chefcoats' AND
    products.styleno=sizeoption.styleno AND
    > products.styleno=coloroption.styleno
    > GROUP BY products.styleno
    > ORDER BY styleno ASC
    >
    > The Detail Recordset:
    > SELECT products.itemID, products.category,
    products.styleno,
    products.name,
    > products.description, products.ourprice,
    products.imageTH, products.image,
    > sizeoption.size, coloroption.color
    > FROM products, sizeoption, coloroption
    > WHERE itemID=colname AND
    products.styleno=sizeoption.styleno AND
    > products.styleno=coloroption.styleno
    >
    > I tried using the GROUP BY on the detail page, but then
    it only showed
    one
    > size and color from the dynamic drop down list. I tried
    changing the
    field
    > name "styleno" in the other tables to be unique,
    however, I was using the
    table
    > identifer. I tried using the JOIN command instead of the
    WHERE clause and
    that
    > didn't help either.
    >
    > On the detail page, the customer is supposed to click on
    the Size box and
    see
    > sizes XSM - 6XL ONLY ONE TIME. and then be able to click
    on the Color
    option
    > and see White, Black, Red ONE TIME.
    >
    > Is this possible?
    >
    > Thank you for giving your time to read this.!
    > Evie
    >
    >

  • Generate a where clause with outer join criteria condition: (+)=

    Hi,
    In my search page, I use Auto Customization Criteria mode, and I build where clause by using get Criteria():
    public void initSrpQuery(Dictionary[] dic, String userName) {
    int dicSize = dic.length;
    StringBuffer whereClause = new StringBuffer(100);
    Vector parameters = new Vector(5);
    int clauseCount = 0;
    int bindCount = 1;
    for(int i=0; i < dicSize; i++){
    String itemName = (String)(dic.get(OAViewObject.CRITERIA_ITEM_NAME));
    Object value = dic[i].get(OAViewObject.CRITERIA_VALUE);
    String joinCondition = (String)dic[i].get(OAViewObject.CRITERIA_JOIN_CONDITION);
    String criteriaCondition = (String)dic[i].get(OAViewObject.CRITERIA_CONDITION);
    String criteriaDataType = (String)dic[i].get(OAViewObject.CRITERIA_DATATYPE);
    String viewAttributename = (String)dic[i].get(OAViewObject.CRITERIA_VIEW_ATTRIBUTE_NAME);
    String columnName = findAttributeDef(viewAttributename).getColumnNameForQuery();
    if((value != null) /*&& (!("".equals((String).trim())))*/){
    if(clauseCount > 0){
    whereClause.append(" AND ");
    whereClause.append(columnName + " " + criteriaCondition + " :");
    whereClause.append(++bindCount);
    parameters.addElement(value);
    clauseCount++;
    If I want to generate following where clause:
    select
    ,emp.name
    ,emp.email
    ,emp.salesrep_number
    ,comp.name
    ,gs.srp_goal_header_id
    ,gs.status_code
    ,gs.start_date
    ,gs.end_date
    from g2c_goal_shr_emp_assignments_v emp
    ,jtf_rs_salesreps rs
    ,xxg2c_srp_goal_headers_all gs
    ,cn_comp_plans_all comp
    where 1 = 1
    and rs.salesrep_id = gs.salesrep_id (+)
    and gs.comp_plan_id = comp.comp_plan_id (+)
    and gs.period_year (+) = :1 -- :1 p_fiscal_year
    How can I generate a where clause with outer join : gs.period_year (+) = :1 ? Will I get '(+)=' from get(OAViewObject.CRITERIA_CONDITION)?
    thanks
    Lei

    If you are using SQL-Plus or Reports you can use lexical parameters like:
    SELECT * FROM emp &condition;
    When you run the query it will ask for value of condition and you can enter what every you want. Here is a really fun query:
    SELECT &columns FROM &tables &condition;
    But if you are using Forms. Then you have to change the condition by SET_BLOCK_PROPERTY.
    Best of luck!

  • Merge Join Cartesian performing bad on 10g

    Hello All,
    I have a merge join cartesian query that took seconds in 8i. Once the database was upgraded to 10g, the same query is taking hours. In looking at the explain plans, it looks like the access paths are identical.
    Has anyone encountered this issue?
    Thanks.

    Sometimes the cost-based optimizer will do cartesian joins to optimize a query. Seeing the word "cartesian" in a query plan is still a major red flag to my eyes. Also, performance changes between versions are usually expected, though most people complain about 9i to 10g results these days :)
    Are you sure you need to be doing a cartesian join at all? As Fly pointed out they have a bad reputation, and yours must be running badly as per your post. I personally get more efficient results from hash joins over sort merges these days so that's something you can look at.
    Try variations on your query to generate execution plans to see if you can get better results. Don't forget to actually time results since plan statistics have been known to be out-of-touch with actual run performance.
    Good luck!

  • Is merge join cartesian more cpu intensibe than nested loop ?

    Hi,
    just wonderning which access method is more cpu intensive , lets supposed we got 2 the same row sources and doing joing via merge join cartesian and next case is nested loop .
    I know NL can be cpu intensive because of tight loop access , but what abour MJC ?
    I can see bufferd sort but not sure is that cpu friendly ?
    Regards
    GregG

    Hi,
    I think in your case it's more accurate to compare a NESTED LOOP (NL) to a MERGE JOIN (MJ), because CARTESIAN MERGE JOIN is a rather special case of MJ.
    Merge join sorts its inputs before combining them, and it could be efficient when one or both of inputs are already sorted.
    Regarding your question (which is more CPU intensive):
    1) if MERGE JOIN involves disk spills, then CPU is probably irrelevant, because disk operations are much more expensive
    2) the amount of work to combine rowsources via a MJ depends on how well they are aligned with respect to each other, so I don't think it can be expressed via a simple formula.
    For nested loops, the situation is much more simple: you don't need to do any special work do combine the rowsource, so the cost is just the sum of the cost acquiring the outer rowsource plus the number of iterations times the cost of one iteration. If the data is read from disk, then CPU probably won't matter much, if most of reads are logical ones than CPU becomes of a factor (it's hard to tell how much work CPU will have to do per one logical read because there are two many factors here -- how many columns are accessed, how they are located within the block, are there any expensive math functions applied to any of them etc.)
    Best regards,
    Nikolay

  • Where clause and order by to DAO classes

    Hi
    Is it ok(I mean design wise) to pass the 'where clause' conditions and order by clause as a parameter to the method of DAO class?

    Well, I would suggest you write seperate methods in your dao , one to select data without the where clause and one to select data with the where clause thrown in. If you have different 'where' clauses for selecting different kinds of data, have that many dao methods. The dao methods being specific know exactly what is the data that's coming in.
    Lets assume you have a list of purchase orders and each purchase order is indetified by a unique id called PURCHASE_ORDER_ID.
    1. The following code would populate a purchase order's details given an id.
    private statis final String QUERY_1 = "select * from PURCHASE_ORDERS where PURCHASE_ORDER_ID = ? ";
    PurchaseOrderModel getPurchaseOrderData(long poId){
         //get a prepared statement from your connection
         PreparedStatement pst = conn.prepareStatement(QUERY_1);
         //set the poId passed as params to your query
         pst.setLong(1, poId);
         ResultSet rs = pst.executeQuery();
         if(rs.next()){
              //populate data into a model          
         finally{
              //clean up resources
         return model;    
    }2. The following code would return a list of PurchaseOrderModel's whose shipping date falls between a set of dates selected by the user.
    private statis final String QUERY_2 = "select * from PURCHASE_ORDERS where SHIPPING_DATE between ? and ? ";
    PurchaseOrderModel getPurchaseOrdersBetweenDates(list bindValues){
         //get a prepared statement from your connection
         PreparedStatement pst = conn.prepareStatement(QUERY_1);
         //set the dates passed as params to your query
         //we know that the List ought to contain only 2 dates
         pst.setDate(1, (Date)bindValues.get(0));
         pst.setDate(2, (Date)bindValues.get(1));
         ResultSet rs = pst.executeQuery();
         if(rs.next()){
              //iterate and populate data into a model          
              //add model to a list
         finally{
              //clean up resources
         return list;    
         3. This is more interesting - the dao method searches a list of Purchase Orders starting with a set of specific words. The words themselves may be one or many. This means that the number of '?' in your prepared statement may be dynamic. Each element of the list is a String that contains the start substring of a purcahse order name. For example - the list may contain elements like ["a", "ab", "c", "gh"] and the dao method returns all purchase order starting with these names.
    private statis final String QUERY_3 = "select * from PURCHASE_ORDERS where ";
    PurchaseOrderModel getPurchaseOrderNameMatches(list bindValues){
         //construct the query dynamically
         StringBuffer query = new StringBuffer(QUERY_3);
         int count = 0;
         for(Iterator itr = bindValues.iterator(); itr.hasNext();;){
              String value = (String)itr.next();
              query.append ("name like 'value%' ");
              if (count != 0 and (count+1 != bindValues.length)){
                   query.append(" or ");
              count ++;          
         //get a prepared statement from your connection
         PreparedStatement pst = conn.prepareStatement(query.toString());     
         ResultSet rs = pst.executeQuery();
         if(rs.next()){
              //iterate and populate data into a model          
              //add model to a list
         finally{
              //clean up resources
         return list;    
    To sum up,
    1. You need as many methods as you have different kinds of searches (one method for each kind of 'where' clause).
    2. The ejb/business layer would examine the data and decide on which method to call.
    3. Increases coding effort, but makes the code clean and readable. Each layer does it's job. Thus we dont have ejbs forming 'where' clauses and so on.
    Having said that, it really is your decision - you should take into consideration the following factors -
    1. How big is the project ? If its a huge codebase developed by many people, then segregate the responsibilities clearly in each layer as I have outlined. For a small scale project, you could go with your approach.
    2. Whats the take on maintenance and future add-ons ? Do you see the codebase growing with time ?
    3. Is your project a commercial one - is it a product that needs to be maintained or is it a one-off development - develop once and you are done with it.
    4. What are the design considerations ? Is somebody going to audit code for quality ? Or is it a academic one ?
    You should take into account all these before deciding to go one way or the other.
    A general thumb rule should be that you should be convinced that your code readable (maintainable), scalable and efficient. Anything that you do towards these ends is good code/design despite what people/books/patterns say, IMO.
    cheers,
    ram.

  • Mutilple Filter Objects - Changing where clause and or

    Is it possible to have a query as below using filter commands.
    (obj1 = 'value11' and obj2 = 'value21')
    or
    (obj1 = 'value12' and obj2 = 'value22')
    or
    The objective is to manipulate the where clause and , or .
    Thanks in Advance
    Bhanu Mohanty

    Hi Bhanu,
    to reach what you want it's necessary to build a virtual characteristic.
    The new characteristic will be populated via coding during runtime of your query. Another possibility (as mentioned before in this forum by Siegfried Szameitat) is to create a new characteristic in your cube that contains field1 and field2 concatenated. With the first scenario, you don’t need a reloading of your cube, with second one this is necessary.
    Hope this helps.
    Bye,
    Roberto

  • Complex Inner Join and subquery on outer where clause on inner join?

    The DDL for this post was too big and I had to put on my website:
    http://www.harbortownsolutions.com/DDLForDORTable.txt
    My goal is to create a report of sales data for 116 stores containing daily sales and guest count to last years. My challenge is I'm pulling data from the same table but with different dates to get data from last year and Week to date data from last year.
    Dates used for reports are:
    SalesDate = 6/4/2009
    SalesDateForLastYear = 6/5/2008
    SalesDateBeginningOfWeek = 6/1/2009
    SalesDateBginningOFWeekLastYear = 6/2/2008
    PSEUDOQUERYS:
    ---======= DOLLAR VARIANCE = You Said you have $100 worth of meat(inventory) but you only have $50 worth of meat
    SELECT
        BUSI_DATE as BusinessDate,
        ORACLE_KEY as StoreID,
        FIELD1  as Sales,
        FIELD2  as GuestCount,
        FIELD3  as DollarVariance,
        FIELD4  as Cars
    FROM MYDAILYTOTALS
    WHERE Busi_date = SalesDate
       AND ORACLE_KEY IN (SELECT StoreID From MyStores);
    -======= ONLY Guest count and Sales are needed in comparisons against last year   
    ---======    Last YEar dates = corresponding dates for this year ie Tuesday of this
    week matched to Tuesday of last year (except for leap year)
    SELECT
        ORACLE_KEY as StoreID
        FIELD1  as SalesLastYear
        FIELD2  as GuestCountLastYear  
    FROM MYDAILYTOTALS
    WHERE Busi_date = SalesDateForLastYear
       AND ORACLE_KEY IN (SELECT StoreID From MyStores);
    SELECT
        ORACLE_KEY as StoreID
        SUM(FIELD1)  as WeekToDateSales
        SUM(FIELD2)  as WeekToDateGuestCount 
    FROM MYDAILYTOTALS
    WHERE Busi_date BETWEEN SalesDateBeginningOfWeek and SalesDate
       AND ORACLE_KEY IN (SELECT StoreID From MyStores)
    GROUP BY ORACLE_KEY
       --======= 
    SELECT
        ORACLE_KEY as StoreID
        SUM(FIELD1)  as WeekToDateSalesLastYear
        SUM(FIELD2)  as WeekToDateGuestCountLastYear 
    FROM MYDAILYTOTALS
    WHERE Busi_date BETWEEN SalesDateBeginningOfWeekLastYear and SalesDateLastYear
       AND ORACLE_KEY IN (SELECT StoreID From MyStores)
    GROUP BY ORACLE_KEY   Question: Since they all use the same store nbrs, do I need to specify on each query? CAn't i jsut specify once on outer query Where clause?
    Also How would I integrate the following script from HOEK:
    See How do I set 1 field based on another field's value
    It gets a record for each store of the 116 stores from inventory database. There were 2 situations that were addressed by Hoeks code:
    For each of the 116 stores in store table, there must be 1 and only
    1 inventory record to match the MyStoreTotals record. However, sometimes there will be no inventory record.
    and sometimes there will be 2 (in a case where a manager updates database
    after daily processing) records. if so, the record with Is_posted = 1
    is the one that should be included in query. The following accomplishes this:
    -- chr(39) is single quote
    Select StoreId,
             DollarVariance
      from   (select store.storeid,
                       case
                              when inv.storeid is null then 'None'
                              when inv.is_posted = 0 then 'NP'
                              else chr(39)||inv.total_dol_var||chr(39)
                        end as DollarVariance,
                        row_number() over (partition by store.storeid order by inv.is_posted desc) rn 
                   from  myInven inv
                   right outer join mystores  store
                                  on store.storeid = inv.fk_str_main_id
                                  and inv.busi_date = to_date(SalesDate, 'dd-mon-yyyy'))
          where rn = 1;      Do I put this query on the where clause of the outer query of do I put it on a JOIN clause?

    Here is Part 2: The Insert for totals table
    ---=== POPULATE TOTALS
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',21,3163.79,189.83,0,-190.7);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',22,2747.25,255.37,0,-235.95);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',23,4182.74,388.74,0,-248.47);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',24,4551.5,423.05,0,-467.46);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',25,2785.13,258.8,0,-199.85);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',27,3409.31,317,0,-175.18);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',28,3808.61,228.6,0,-233.04);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',29,3416.97,239.35,0,-110.77);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',30,2133.4,128.13,0,-178.37);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',31,2261.27,210.14,0,-272.39);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',32,2258.18,135.6,0,-83.01);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',33,3908.26,312.71,0,-121.41);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',34,3035.45,273.38,0,-97.8);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',35,3088.44,185.5,0,-123.56);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',36,4255.4,395.48,0,-206.16);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',37,6331.13,380.01,0,-505.47);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',38,3552.78,319.94,0,-168.33);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',39,2991.44,277.96,0,-228.98);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',40,0,0,0,0);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',41,3825.03,355.49,0,-204.93);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',42,3843.16,357.16,0,-237.5);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',43,2981.78,179,0,-45.97);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',61,4504.6,270.32,0,-362.49);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',62,4034.46,242.1,0,-260.95);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',64,1811.58,168.39,0,-108.78);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',65,2271.46,211.04,0,-117.32);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',66,2336.32,217.02,0,-95.28);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',67,4208.13,410.39,0,-197.3);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',68,2803.55,273.31,0,-154.11);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',69,1702.81,153.46,0,-98.58);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',70,4098.3,399.51,0,-208.42);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',71,1952.1,190.26,0,-59.51);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',72,4716.07,283.07,0,-428.18);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',73,2897.56,269.43,0,-329.79);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',74,0,0,0,0);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',75,3438.59,319.84,0,-344.96);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',76,3016.7,280.67,0,-106.39);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',78,4228.31,253.73,0,-249.33);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',81,4152.43,249.33,0,-135.87);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',82,3772.42,350.69,0,-174.02);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',83,2594.06,241.02,0,-196.18);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',101,3868.21,232.21,0,-360.36);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',141,2246.55,134.92,0,-100.97);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',181,2357.75,219.07,0,-205.8);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',202,2724.47,163.47,0,-107.54);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',203,3225.11,193.67,0,-143.19);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',204,2641.28,158.55,0,-131.84);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',205,4644.56,278.72,0,-260.48);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',206,3859.62,231.76,0,-203.47);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',221,3647.04,355.53,0,-186.82);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',222,2446.59,227.42,0,-172.67);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',223,3439.52,319.61,0,-264.23);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',224,3121.7,290.07,0,-284.98);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',241,2858.38,228.81,0,-279.91);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',243,4983.38,299.22,0,-370.89);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',244,2970.69,178.37,0,-189.97);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',245,5829.93,349.97,0,-215.5);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',246,4344.78,260.79,0,-120.38);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',247,4154.77,249.52,0,-175.08);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',248,4875.21,292.58,0,-296.04);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',249,4041.39,242.6,0,-99.91);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',250,2933.45,176.04,0,-208.56);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',251,5448.82,327.13,0,-358.71);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',252,2429.18,224.88,0,-136.03);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',253,2884.63,173.14,0,-83.95);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',254,3708.4,222.64,0,-318.75);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',255,3722.19,346.22,0,-204.4);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',256,3834.23,230.16,0,-245.91);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',257,3456.4,321.22,0,-259.7);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',258,3018.22,181.16,0,-146.83);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',259,2807.65,260.97,0,-241.13);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',260,3424.99,318.21,0,-229.06);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',262,3782.55,351.66,0,-174.42);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',263,2570.84,239.08,0,-184.58);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',264,3904.8,234.22,0,-235.03);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',265,2853.7,286.29,0,-253.16);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',266,3246.72,194.76,0,-237.36);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',267,3712.25,417.97,0,-257.5);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',268,4141.22,248.53,0,-68.98);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',269,3693.64,221.77,0,-228.45);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',271,3775.03,226.8,0,-213.14);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',272,2870.1,172.27,0,-514.23);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',273,3132.8,188.22,0,-148.05);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',274,2454.86,147.31,0,-142.1);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',276,3627.72,337.17,0,-232.38);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',277,3118.79,187.21,0,-152.68);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',278,3360.09,302.7,0,-220.63);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',279,2478.11,230.44,0,-192.49);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',280,3252.54,302.38,0,-213.72);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',281,3654.62,219.44,0,-164.95);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',282,3159.75,189.72,0,-168.68);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',285,2839.63,241.67,0,-238.7);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',286,3468.01,322.29,0,-186.25);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',287,3546.42,329.74,0,-160.14);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',289,2331.57,174.44,0,-293.47);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',290,1702.25,131.62,0,-101.72);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',291,3969.8,369.02,0,-253.26);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',292,2265.99,210.52,0,-182.05);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',293,3234.72,258.74,0,-137.08);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',294,3932.19,354.24,0,-201.15);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',295,3754.2,225.46,0,-307.99);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',296,3885.37,235.24,0,-293.24);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',298,2479.43,148.86,0,-207.68);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',321,3542.26,212.71,0,-206.25);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',362,1540.87,142.53,0,-101.3);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',363,2798.87,314.66,0,-356.52);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',364,2658.94,212.7,0,-159.29);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',365,0,0,0,0);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',381,3155.66,189.48,0,-229.18);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',441,1389.79,98.92,0,-77.94);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',461,1874.39,149.82,0,-298.2);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',462,2539.64,161.32,0,-206.73);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',501,3861.36,357.29,0,-286.17);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',521,3449.41,318.93,0,-182.83);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',522,2938.99,176.51,0,-149.65);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',523,4352.54,261.29,0,-333.7);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',524,4163.36,385.54,0,-352.01);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',544,2481.37,260.53,0,-29.9);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',564,2344.38,211.07,0,-153.02);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-08',624,3136.78,188.29,0,-199.51);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',21,3250.89,195.13,0,-161.39);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',22,2595.78,241.23,0,-159.05);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',23,4533.49,421.43,0,-348.07);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',24,5337.24,496.17,0,-475.37);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',25,3328.26,309.42,0,-172.65);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',27,3680.53,342.16,0,-159.81);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',28,3850.95,231.21,0,-343.33);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',29,3470.75,243.07,0,-112.19);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',30,2799.58,168.14,0,-321.17);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',31,2241.6,208.23,0,-249.08);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',32,2744.05,164.74,0,-138.96);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',33,3987.38,319.11,0,-111.6);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',34,2996.06,269.94,0,-135.31);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',35,3502.73,210.32,0,-100.55);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',36,3553.27,330.15,0,-176.07);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',37,6387.03,383.52,0,-497.73);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',38,3295.64,296.86,0,-183.05);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',39,2891.77,268.67,0,-79.79);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',40,0,0,0,0);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',41,3806.24,354.67,0,-183.84);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',42,3572.47,332.13,0,-176.78);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',43,3231.48,193.91,0,-101.76);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',61,4812.72,289.03,0,-309.85);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',62,4245.8,254.83,0,-241.36);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',64,1925.79,179.05,0,-81.31);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',65,2350.08,218.44,0,-49.03);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',66,2440.74,226.71,0,-103.36);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',67,4154.7,405.04,0,-142.79);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',68,3177.54,309.78,0,-203.25);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',69,1602.51,144.48,0,-89.2);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',70,4332.09,422.2,0,-279.47);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',71,2266.95,220.94,0,-147.58);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',72,5270.73,316.57,0,-636.12);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',73,2982.05,277.08,0,-292.33);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',74,0,0,0,0);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',75,3708.11,344.64,0,-537.87);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',76,2984.98,277.59,0,-163.33);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',78,4308.12,258.69,0,-242.15);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',81,4122.56,247.58,0,-201.33);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',82,3816.69,354.86,0,-219.83);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',83,2587.89,240.53,0,-225.54);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',101,4369.67,262.3,0,-206.67);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',141,2603.25,156.3,0,-101.35);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',181,2147.47,199.55,0,-216.75);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',202,2622.75,157.5,0,-135.47);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',203,3574.63,214.73,0,-219.38);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',204,2906.92,174.56,0,-110.08);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',205,4895.05,293.87,0,-277.18);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',206,3520.21,211.2,0,-269.1);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',221,4079.8,397.83,0,-135.79);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',222,2420.63,225.04,0,-218.93);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',223,3071.77,285.46,0,-204.44);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',224,3162.39,293.88,0,-364.17);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',241,3207.99,256.68,0,-150.69);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',243,5195.78,311.98,0,-257.23);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',244,3297.07,198.05,0,-174.03);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',245,5968.82,358.41,0,-319.01);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',246,4200.59,252.23,0,-158.47);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',247,4070,244.44,0,-192.64);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',248,4968.23,298.1,0,-230.1);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',249,4693.38,281.83,0,-51.24);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',250,3101.72,186.19,0,-65.67);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',251,5772.54,346.49,0,-370.65);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',252,2616.47,242.24,0,-313.94);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',253,3471.22,208.33,0,-125.65);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',254,3878.21,232.87,0,-148.1);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',255,3863.12,359.29,0,-259.09);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',256,3710.4,222.76,0,-158.92);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',257,2998.68,278.72,0,-209.98);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',258,3589.82,215.49,0,-146.1);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',259,2767.48,257.21,0,-196.7);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',260,2973.28,276.2,0,-199.43);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',262,3859.64,358.89,0,-400.09);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',263,2812.9,261.43,0,-180.02);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',264,3916.29,234.97,0,-129.04);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',265,2756.12,276.52,0,-100.22);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',266,3164.38,190.06,0,-166.11);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',267,3510.19,395.32,0,-419.08);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',268,4404.09,264.47,0,-119.09);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',269,3719.31,223.16,0,-233.2);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',271,4072.41,244.37,0,-337.97);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',272,3547.26,212.98,0,-242.38);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',273,3055.74,183.41,0,-250.05);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',274,2494.52,149.72,0,-118.34);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',276,3547.39,329.69,0,-254.4);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',277,2904.89,174.45,0,-169.73);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',278,3437.7,309.83,0,-221.15);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',279,3142.29,292.08,0,-247.97);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',280,3470.57,322.59,0,-286.45);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',281,4075.15,244.63,0,-313.42);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',282,2873,172.52,0,-150.44);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',285,2951.56,251.12,0,-294.04);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',286,3803.64,353.56,0,-244.53);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',287,3402.96,316.4,0,-164.22);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',289,2514.92,188.12,0,-238.77);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',290,1797.42,138.89,0,-196.18);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',291,3904.15,362.83,0,-246.27);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',292,2414.91,224.34,0,-109.66);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',293,3336.49,266.85,0,-232.16);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',294,3761.44,338.74,0,-179.55);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',295,4363.6,262.12,0,-319.81);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',296,4274.18,258.43,0,-222.11);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',298,2823.18,169.51,0,-315.66);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',321,4000.01,240.05,0,-191.67);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',362,1944.95,179.72,0,-191.07);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',363,3171.3,356.66,0,-363.11);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',364,3057.67,244.75,0,-124.49);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',365,0,0,0,0);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',381,3140.8,188.58,0,-251.87);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',441,1507.47,107.24,0,-62.57);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',461,1609.21,128.6,0,-289.64);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',462,2660.68,168.81,0,-253.25);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',501,4140.65,383.21,0,-525.13);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',521,3801.87,352.02,0,-325.62);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',522,3456.49,207.58,0,-282.41);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',523,4413.29,264.6,0,-417.35);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',524,4502.73,416.91,0,-429.19);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',544,2800.89,294.13,0,-31.98);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',564,2632.22,237.14,0,-174.72);
    INSERT INTO MYDAILYTOTALS VALUES('03-JUN-08',624,3006.17,180.49,0,-186.61);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',21,3313.37,198.82,501.41,148.71);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',32,2233.4,134.06,529.18,81.52);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',39,3151.53,292.94,445.76,200.74);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',43,3260.15,195.77,708.43,138.56);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',66,2968.89,275.97,541.77,329.89);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',69,2227.11,200.54,378.5,62.78);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',73,2596.94,241.55,353.28,62.28);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',101,4263.98,255.93,555.08,339.94);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',141,2326.62,139.65,514.13,18.35);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',202,2663.65,159.94,650.3,98.32);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',206,3862.53,231.85,700.72,135.09);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',221,3458,337.07,537.24,111.94);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',223,3244.05,301.4,504.12,78.03);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',224,3271.02,304.12,488.82,142.74);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',243,4582.04,275.73,757.99,173.21);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',244,3075.06,184.7,559.75,254.56);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',245,5770.79,346.51,745.04,232.29);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',247,4445.29,266.95,707.99,148.44);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',250,2993.46,179.71,716.03,77.52);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',254,3439.15,206.53,455.68,103.27);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',258,3199.55,192.22,656.15,380.93);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',262,3863.19,359.27,530.18,57.15);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',264,4014.15,241.09,715.7,210.46);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',267,3508.58,394.9,622.73,109.92);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',271,4334.5,260.16,607.84,322.44);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',272,3402.47,204.25,504.9,230.47);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',273,3260.08,195.81,620.68,203.57);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',282,3182.51,191.16,557.39,177.95);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',292,2103.39,195.46,366.92,95.33);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',298,2997.51,179.87,452.71,210.64);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',362,1614.2,149.22,329.87,141.86);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',363,3058.98,344.1,523.53,259.03);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',523,3776.49,226.8,533.46,376.94);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',524,4720.08,437.05,554.55,320.96);
    INSERT INTO MYDAILYTOTALS VALUES('01-JUN-09',564,2725.49,245.4,419.73,134.96);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',22,2482.4,230.46,1126.91,42.33);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',23,4907.83,456.19,1254.74,305.28);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',27,3170.7,294.64,990.07,74.02);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',34,2660.45,239.48,1046.41,64.37);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',43,3459.94,207.57,1349.89,114.96);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',62,4515.62,271.13,1234.8,125.26);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',65,2196.06,204.05,1010.08,60.71);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',66,2558.77,237.84,1031.84,76.4);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',68,2677.87,261.12,950.73,184.17);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',69,2165.68,195.01,786.06,62.33);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',78,4562.37,274.06,1386.15,135.12);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',141,2690.6,161.65,1118.96,36.43);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',181,2321.7,215.62,827.14,50.56);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',244,3312.27,198.84,1099.22,235.38);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',251,6012.15,360.89,1786.03,489.65);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',252,1823.33,164.16,702.65,78.91);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',260,3030.32,281.47,958.58,90.78);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',262,4198.03,390.37,1111.2,57.21);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',263,2463.36,229.01,1010.05,39.46);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',271,4571.16,274.35,1256.94,162.23);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',276,3244.67,301.41,926.42,70.05);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',277,3650.92,219.3,1225.24,184.51);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',281,3915.25,235.15,1364.07,207.56);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',282,3207.09,192.59,1279.52,116.07);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',289,2509.67,187.63,1156.46,129.59);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',290,1840.89,133.03,885.45,166.21);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',291,3860.49,358.79,1157.38,86.91);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',295,3989.96,239.65,1258.06,239.39);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',298,2748.82,165.08,979.23,290.44);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',321,3626.59,217.84,1547.6,186.81);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',381,3030.78,181.96,977.68,246.34);
    INSERT INTO MYDAILYTOTALS VALUES('02-JUN-09',521,3349.57,310.04,1184.6,87.48);

  • Where clause and joins

    HI all,
    If i Have a select statement that needs two different tables
    and a where clause with only 1 join and the rest of conditions dependent on only 1 table such as:
    select .... from table a, table b
    where a.col1 = b.col1
    and b.col2 some condition
    and b.col3 some condition;
    is it better/optima for performancel for me to have the join right at the beginning of the where clause or after table b has been filtered out such as:
    select ... from table a, table b
    where b.col2 some condition
    and b.col3 some condition
    and a.col1 = b.col1

    Hi,
    The order of conditions in a WHERE clause doesn't effect performance; the Cost-Based Optimizer will decide how to perform them.
    The order can make a difference on how easy it is to understand and maintain the code. I find ANSI join syntax far better for this:
    select      ...
    from      table      a
    join     table      b     on     a.col1     = b.col1
    where      b.col2  <some condition>
    and      b.col3  <some condition>
    ;

  • Need help with WITH Clause and Outer-Joins

    Hi,
    I have been struggling to understand these queries.
    C:\>sqlplus /nolog
    SQL*Plus: Release 10.2.0.1.0 - Production on Thu Oct 20 15:28:33 2011
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    SQL> conn hr@xe
    Enter password:
    Connected.
    SQL> with week as ( select * from (select 1 item, 10 qty, 1 week from dual ))
      2  select main.item
      3       , week1.qty qty1
      4       , week2.qty qty2
      5    from week week1
      6       , week week2
      7       , ( select 1 item from dual ) main
      8   where main.item = week1.item (+)
      9     and week1.week (+) = 1
    10     and main.item = week2.item (+)
    11     and week2.week (+) = 2
    12     ;
          ITEM       QTY1       QTY2
             1
    SQL> with week as ( select 1 item, 10 qty, 1 week from dual )
      2  select main.item
      3       , week1.qty qty1
      4       , week2.qty qty2
      5    from week week1
      6       , week week2
      7       , ( select 1 item from dual ) main
      8   where main.item = week1.item (+)
      9     and week1.week (+) = 1
    10     and main.item = week2.item (+)
    11     and week2.week (+) = 2
    12     ;
          ITEM       QTY1       QTY2
             1         10
    SQL>I don't understand why the first query won't show the result for QTY1. The only difference they have is that the first uses an additional inline view.
    Can someone please explain the reason behind.
    Thanks,
    Allen
    Edited by: Allen Sandiego on Oct 20, 2011 3:31 PM
    Enclosed in CODE tags.

    Also in 10.2.0.4.0. The predicate part contains a clue about the transformation
    mhouri > select * from v$version;
    BANNER                                                                         
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi               
    PL/SQL Release 10.2.0.4.0 - Production                                         
    CORE     10.2.0.4.0     Production                                                     
    TNS for Solaris: Version 10.2.0.4.0 - Production                               
    NLSRTL Version 10.2.0.4.0 - Production                                         
    mhouri > with week as ( select * from (select 1 item, 10 qty, 1 week from dual ))
      2        select
      3               main.item
      4             , week1.qty qty1
      5             , week2.qty qty2
      6          from week week1
      7             , week week2
      8             , ( select 1 item from dual ) main
      9         where main.item = week1.item (+)
    10           and week1.week (+) = 1
    11          and main.item = week2.item (+)
    12          and week2.week (+) = 2;
          ITEM       QTY1       QTY2                                                                                       
             1                                                                                                             
    mhouri > select * from table(dbms_xplan.display_cursor);
    | Id  | Operation                  | Name                        | Rows  | Bytes | Cost (%CPU)| Time     |             
    |   0 | SELECT STATEMENT           |                             |       |       |     8 (100)|          |             
    |   1 |  TEMP TABLE TRANSFORMATION |                             |       |       |            |          |             
    |   2 |   LOAD AS SELECT           |                             |       |       |            |          |             
    |   3 |    FAST DUAL               |                             |     1 |       |     2   (0)| 00:00:01 |             
    |   4 |   MERGE JOIN OUTER         |                             |     1 |    18 |     6   (0)| 00:00:01 |             
    |   5 |    NESTED LOOPS OUTER      |                             |     1 |     9 |     4   (0)| 00:00:01 |             
    |   6 |     FAST DUAL              |                             |     1 |       |     2   (0)| 00:00:01 |             
    |*  7 |     VIEW                   |                             |     1 |     9 |     2   (0)| 00:00:01 |             
    |   8 |      TABLE ACCESS FULL     | SYS_TEMP_0FD9D6631_72948EFD |     1 |    39 |     2   (0)| 00:00:01 |             
    |   9 |    BUFFER SORT             |                             |     1 |     9 |     4   (0)| 00:00:01 |             
    |* 10 |     VIEW                   |                             |     1 |     9 |     2   (0)| 00:00:01 |             
    |  11 |      TABLE ACCESS FULL     | SYS_TEMP_0FD9D6631_72948EFD |     1 |    39 |     2   (0)| 00:00:01 |             
    Predicate Information (identified by operation id):                                                                    
       7 - filter(("WEEK1"."ITEM"=1 AND "WEEK1"."WEEK"=1))                                                                 
      10 - filter(("WEEK2"."ITEM"=1 AND "WEEK2"."WEEK"=2))                                                                 
    33 rows selected.
    mhouri > with week as ( select * from (select 1 item, 10 qty, 1 week from dual ))
      2        select /*+ no_query_transformation */
      3               main.item
      4             , week1.qty qty1
      5             , week2.qty qty2
      6          from week week1
      7             , week week2
      8             , ( select 1 item from dual ) main
      9         where main.item = week1.item (+)
    10           and week1.week (+) = 1
    11          and main.item = week2.item (+)
    12          and week2.week (+) = 2;
          ITEM       QTY1       QTY2                                                                                       
             1         10                                                                                                  
    mhouri > select * from table(dbms_xplan.display_cursor);
    | Id  | Operation                  | Name                        | Rows  | Bytes | Cost (%CPU)| Time     |             
    |   0 | SELECT STATEMENT           |                             |       |       |     9 (100)|          |             
    |   1 |  TEMP TABLE TRANSFORMATION |                             |       |       |            |          |             
    |   2 |   LOAD AS SELECT           |                             |       |       |            |          |             
    |   3 |    VIEW                    |                             |     1 |     9 |     2   (0)| 00:00:01 |             
    |   4 |     FAST DUAL              |                             |     1 |       |     2   (0)| 00:00:01 |             
    |*  5 |   HASH JOIN OUTER          |                             |     1 |    21 |     7  (15)| 00:00:01 |             
    |*  6 |    HASH JOIN OUTER         |                             |     1 |    12 |     5  (20)| 00:00:01 |             
    |   7 |     VIEW                   |                             |     1 |     3 |     2   (0)| 00:00:01 |             
    |   8 |      FAST DUAL             |                             |     1 |       |     2   (0)| 00:00:01 |             
    |*  9 |     VIEW                   |                             |     1 |     9 |     2   (0)| 00:00:01 |             
    |  10 |      TABLE ACCESS FULL     | SYS_TEMP_0FD9D6630_72948EFD |     1 |     9 |     2   (0)| 00:00:01 |             
    |* 11 |    VIEW                    |                             |     1 |     9 |     2   (0)| 00:00:01 |             
    |  12 |     TABLE ACCESS FULL      | SYS_TEMP_0FD9D6630_72948EFD |     1 |     9 |     2   (0)| 00:00:01 |             
    Predicate Information (identified by operation id):                                                                    
       5 - access("MAIN"."ITEM"="WEEK2"."ITEM")                                                                            
       6 - access("MAIN"."ITEM"="WEEK1"."ITEM")                                                                            
       9 - filter("WEEK1"."WEEK"=1)                                                                                        
      11 - filter("WEEK2"."WEEK"=2)                                                                                        
    36 rows selected.Best regards
    Mohamed Houri

Maybe you are looking for

  • BW/ABAP- Function module is called infinitely by Datasource Extractor.

    Hi All, A quick ABAP question related to Function Modules and BW data source extractors. I’ve written a function module to select data from a database and simply output the data as a table. I then created a text Datasource using transaction rso2 and

  • Authority check based on the tables used in a programme

    based on the tables used in a programme can I see authority checks available in the system.If yes how do i go about it .

  • Importing Only New Photos from iPhone?

    Is it possible to import just the new photos from my iPhone to my computer using iPhoto? Every time I connect my iPhone it wants to re-import every photo in my camera roll-- not just the ones that are new since the last import. I don't want to delete

  • How to clean insect dirt off screen

    my Mac sits under a downlight that attracts insects thus I have found insect dirt on the screen - how do I get rid of this dirt please?  Princepony

  • WEB dynpro link

    Hi , In my EP system when i click web able link , two tabs 1.Maintain JCO , Create JCO are disabled , no Jco rfc are not working(when i click ess page it saying Jco rfc not working ) previously it workring fine , can any help me regarding this if log