Where clause of SubQuery

Hello!I beg your pardon for my poor English.
Oracle prompts "invalid month" when running the following sentence:
select *
from xtcs xtcs
where xtcs.csmc like '%month'
and (xtcs.cnq,xtcs.csmc) not in (
select distinct
to_char(add_months(to_date((case when substr(yhjf1.pzh,1,2)>='50' then '19' else '20' end)||substr(yhjf1.pzh,1,4),'yyyymm'),-4),'yyyy') pzcnq
,yhjf1.pzhbs||'month'
from yhjf yhjf1
where yhjf1.pzhbs is not null);
But,oracle runs well when running only the subquery in where clause:
select distinct
to_char(add_months(to_date((case when substr(yhjf1.pzh,1,2)>='50' then '19' else '20' end)||substr(yhjf1.pzh,1,4),'yyyymm'),-4),'yyyy') pzcnq
,yhjf1.pzhbs||'month'
from yhjf yhjf1
where yhjf1.pzhbs is not null;
I have checked the data in the table yhjf.And there are some wrong about field pzh which cause oracle wrong .But the where clause 'yhjf1.pzhbs is not null' can filter them out.I'm being in puzzle now.Please tell me why and how I can do.Thanks very much!

> Sorry,I'm a Chinese.The names originally were in
Chinese.I converted them into alphabets before posting.
I did not think of that option. I'm glad to hear that the names are meaningful to you :-)
> My data is very large and I had not created a
small data set on which the error happens.
To know what the problem is, you will have to identify the rows that are causing the trouble. Once identified, the solution should be simple.
Regards,
Rob.

Similar Messages

  • DECODE is not working in WHERE clause when subquery returns more rows

    Hi Gurus,
    I want to write a query on CCENTERS table(Script given below) and expect the following result:
    1. When I pass a value of 0 for ID, It returns all the rows given in the table.
    2. When I pass a value other than 0, It returns the row for the given value as well as all its child records.
    CCENTER has parent-child relationship in ID and BASE column. I am using a query with DECODE function. but DECODE function in WHERE clause is not capable of handling sub-query with multiple rows.
    VARIABLE ParaCCenter NUMBER
    BEGIN
    :paraccenter:=0;
    END;
    CREATE TABLE ccenters
    (id NUMBER,
    name VARCHAR2(20),
    base number);
    INSERT INTO ccenters VALUES(1,'NUST',null);
    INSERT INTO ccenters VALUES(2,'SEECS',1);
    INSERT INTO ccenters VALUES(3,'NBS',1);
    commit;
    SELECT * FROM ccenters
    WHERE id IN DECODE(:ParaCCenter, 0, id,
    (SELECT id FROM ccenters
    START WITH base=:ParaCCenter
    CONNECT BY PRIOR id = base
    UNION
    SELECT :ParaCCenter FROM dual
    BEGIN
    :paraCCenter:=1;
    END;
    SELECT * FROM ccenters
    WHERE id IN DECODE(:ParaCCenter, 0, id,
    (SELECT id FROM ccenters
    START WITH base=:ParaCCenter
    CONNECT BY PRIOR id = base
    UNION
    SELECT :ParaCCenter FROM dual))
    The result is
    (SELECT id FROM ccenters
    ERROR at line 3:
    ORA-01427: single-row subquery returns more than one row
    How this query can be rewritten for the given functionality. Any response will be highly appreciated.
    Thanks

    And if you want to use DECODE:
    SQL> BEGIN
      2  :paraccenter:=0;
      3  END;
      4  /
    PL/SQL procedure successfully completed.
    SQL> select  *
      2    from  ccenters
      3    where :paraccenter = decode(:paraccenter,0,0,id)
      4  /
            ID NAME                       BASE
             1 NUST
             2 SEECS                         1
             3 NBS                           1
    SQL> BEGIN
      2  :paraccenter:=2;
      3  END;
      4  /
    PL/SQL procedure successfully completed.
    SQL> select  *
      2    from  ccenters
      3    where :paraccenter = decode(:paraccenter,0,0,id)
      4  /
            ID NAME                       BASE
             2 SEECS                         1
    SQL> SY.

  • Subquery in the Where clause

    Can I put a subquery in the where clause, on the left side on the operator?
    This is a multi-row query.
    Like this,
       select a.col1, a.col2, b.col1, b.col2,
                 my_function(a.date1, b.date2) AS GROSSDAYS
       from table1 a
       where ( select ( a.date1 - b.date2 ) as range
                   from     table1 a
                   join      table2 b
                   on       a.col3 = b.col3
                   where rownum =1
                   in ( 1,2,3)
    and  a.col1 = b.col2I need to use a subquery because the column I need does not exist in the table, and I cannot make any changed to the table structure.
    Is what I'm doing possible?
    The subquery is the same as the function I have in the Select clause.

    I tried a subquery in the where clause, but now I'm getting a missing expression error!
       SELECT
            r.complete_flag, r.order_num, r.referral_num, TRUNC(r.referral_datetime) AS referral_datetime,
            r.clinic_specialty, a.appointment_datetime, TRUNC(a.appointment_date_made) AS appt_datemade, a.appointment_status_id,
             scref.scr_rules.calcatcdays(r.referral_datetime,a.appointment_date_made) AS ATCDays  -- returns difference between two dates
    FROM
            referral r,
                                 ( SELECT referral_num,appointment_datetime, appointment_date_made, appointment_status_id
                                      FROM   ( SELECT referral_num, appointment_datetime, appointment_date_made, appointment_status_id,
                                                ROW_NUMBER() OVER (PARTITION BY referral_num
                                                ORDER BY appointment_datetime) rn
                                            FROM   appointment
                                     WHERE rn = 1
                             a
    WHERE r.order_num IS NOT NULL
    AND   ( SELECT adays                      -- THIS IS WHERE I'M GETTING A MISSING EXPRESSION ERROR!!!
           FROM ( SELECT scref.scr_rules.calcatcdays(r.referral_datetime,a.appointment_date_made) AS adays
                    FROM referral r
                     JOIN appointment a
                     ON   a.referral_num = r.referral_num
                     WHERE ROWNUM = 1
           WHERE  adays
          ) = 3
    AND   r.referral_num = a.referral_num(+)
    AND   TRUNC(r.referral_datetime) >= TO_DATE('01-JUL-05','DD-MON-YY')
    AND   TRUNC(r.referral_datetime) <= TO_DATE('31-JUL-05','DD-MON-YY')

  • Order by in subquery ignores where clause

    Following the suggestion to simulate "select first," I did the following:
    select e.*,
    (select * from (select dname from scott.dept d where d.deptno = e.deptno order by dname) t where rownum = 1) dname
    from scott.EMP e;
    The "order by dname" however, cause the subquery to ignore the where clause.
    I know in this case, I can use a first_value() or min(), and it'll always return 1 row b/c of the PK. Still, any idea why it would ignore the where clause in the presence of an order by?
    Thanks

    My output:
    SQL*Plus: Release 10.2.0.1.0 - Production on Fri Mar 31 13:50:54 2006
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    SQL> select (select dname from (select dname from scott.dept d where d.deptno = e.deptno order by dname) t where rownum = 1) dname, e.* from scott.EMP e;
    DNAME EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
    ACCOUNTING 7369 SMITH CLERK 7902 17-DEC-80 800 20
    ACCOUNTING 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
    ACCOUNTING 7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
    ACCOUNTING 7566 JONES MANAGER 7839 02-APR-81 2975 20
    ACCOUNTING 7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
    ACCOUNTING 7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
    ACCOUNTING 7782 CLARK MANAGER 7839 09-JUN-81 2450 10
    ACCOUNTING 7788 SCOTT ANALYST 7566 19-APR-87 3000 20
    ACCOUNTING 7839 KING PRESIDENT 17-NOV-81 5000 10
    ACCOUNTING 7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
    ACCOUNTING 7876 ADAMS CLERK 7788 23-MAY-87 1100 20
    ACCOUNTING 7900 JAMES CLERK 7698 03-DEC-81 950 30
    ACCOUNTING 7902 FORD ANALYST 7566 03-DEC-81 3000 20
    ACCOUNTING 7934 MILLER CLERK 7782 23-JAN-82 1300 10
    14 rows selected.
    SQL> select (select dname from (select dname from scott.dept d where d.deptno = e.deptno) t where rownum = 1) dname, e.* from scott.EMP e;
    DNAME EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
    RESEARCH 7369 SMITH CLERK 7902 17-DEC-80 800 20
    SALES 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
    SALES 7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
    RESEARCH 7566 JONES MANAGER 7839 02-APR-81 2975 20
    SALES 7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
    SALES 7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
    ACCOUNTING 7782 CLARK MANAGER 7839 09-JUN-81 2450 10
    RESEARCH 7788 SCOTT ANALYST 7566 19-APR-87 3000 20
    ACCOUNTING 7839 KING PRESIDENT 17-NOV-81 5000 10
    SALES 7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
    RESEARCH 7876 ADAMS CLERK 7788 23-MAY-87 1100 20
    SALES 7900 JAMES CLERK 7698 03-DEC-81 950 30
    RESEARCH 7902 FORD ANALYST 7566 03-DEC-81 3000 20
    ACCOUNTING 7934 MILLER CLERK 7782 23-JAN-82 1300 10
    14 rows selected.
    SQL>

  • Subquery in dynamic where-clause

    Hi,
    i'm trying to build a dynamic sql-statement in OPEN SQL, which uses a subquery in the dynamic where-clause.
    In the following example code the first select works fine, the second one raises an error.
    report  zerrorforum.
    data:
      l_var_anzahl
    * No Error
    select
       count(*)
    into
       l_var_anzahl
    from
       t000 as t1
    where
       t1~mandt in ( select t2~mandt from t000 as t2 where t2~mandt = t1~mandt ).
    * Error
    select
       count(*)
    into
       l_var_anzahl
    from
       t000 as t1
    where
       ('T1~MANDT IN ( SELECT T2~MANDT FROM T000 AS T2 WHERE T2~MANDT = T1~MANDT )').
    The Error Analysis says the following:
    The exception, which is assigned to class 'CX_SY_DYNAMIC_OSQL_SEMANTICS', was
    not caught and therefore caused a runtime error.  The reason for the exception is:
    The current ABAP program has tried to execute an Open SQL statement
    which contains a WHERE, ON or HAVING condition with a dynamic part.
    The part of the WHERE, ON or HAVING condition specified at runtime in
    a field or an internal table, contains the invalid value "SELECT".
    Is this behaviour documented anywhere? I didn´t find anything.
    Or is it a bug?
    Klaus-Dieter Lueppens

    Hi,
    it's not possible. Here is a quote from ABAP documentation from dynamic WHERE condition.
    A logical expression can be specified as a parenthesized data object cond_syntax that contains the syntax of a logical expression or is initial when the statement is executed. It has been possible since SAP Web AS 6.40 to specify all logical expressions dynamically, with the exception of the evaluation of a subquery.
    Cheers

  • Function in where clause being executed in subquery

    Oracle version 9.2.0.8
    I have a query of the form
    select cola
          ,colb
          ,expensive_function(colb) as colc
      from t
    where cola between 1 and 100This query returns 100 rows very fast.
    When I try to specify a where clause that uses the result of the expensive function the query takes 60 times longer (60 secs). Table t has a million rows.
    Long Query:
    select *
      from (
        select cola
              ,colb
              ,expensive_function(colb) as colc
          from t
         where cola between 1 and 100) t
    where colc = 'XXX'Could it be that Oracle is executing the function for each row in table t? I only want the function executed on the resultset but I can't seem to get it to work.
    Have tried many different hints and forms of the query without success, e.g.
    select *
      from (
        select cola
              ,colb
          from t
         where cola between 1 and 100) t
    where expensive_function(colb) = 'XXX'
    select /*+ NO_PUSH_PRED(t) */ *
      from (
        select cola
              ,colb
          from t
         where cola between 1 and 100) t
    where expensive_function(colb) = 'XXX'Message was edited by:
    SamB

    <s></s>Compare planing of two SQL, and post what is difference?
    @?/rdbms/admin/utlxplan
    explain plan for
    select cola
          ,colb
          ,expensive_function(colb) as colc
      from t
    where cola between 1 and 100
    @?/rdbms/admin/utlxpls
    explain plan for
    select *
       from (
        select cola
              ,colb
              ,expensive_function(colb) as colc
          from t
         where cola between 1 and 100) t
    where colc = 'XXX'
    @?/rdbms/admin/utlxpls
    explain plan for
    select cola
          ,colb
      from t
    where cola between 1 and 100
        and expensive_function(colb)='XXX'
    @?/rdbms/admin/utlxpls                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Where clause problem in a subquery

    I'll try to explain as detailed as possible.
    Given the following set of data and the parameters passed the query must only return one row;
    If the structure_chain is like the parameter passed, then select that row
    If not then strip out the first number in both the parameter and the column,
    e.i., '2.35364194.34889485' becomes '35364194.34889485'
    The select is what is currently in the code and so far I've not been able to get the (new) desired results - customer changed/enhanced requirements
    with TT as
        (select 1 row_no, 22794978 old_child_id, 51755902 new_child_id, '1.35364194' structure_chain from dual union all
         select 2, 22794978, 51755899, '1.23576950' from dual union all
         select 3, 17872962, 51755893, '1.23576950' from dual union all
         select 4, 17872962, 51756065, '1.35364194.34880851' from dual union all
         select 5, 17872962, 51759249, '2.35364194.34880851' from dual union all
         select 6, 17872962, 51759248, '1.23576950.22795468' from dual union all
         select 7, 17872962, 51759250, '2.23576950.22795468' from dual )
    select * from tt
    where old_child_id = &1
    and   &2 like structure_chain ||'%'
    17872962 '2.35364194.34880851'   -- Return row_no 5 
    17872962 '1.23576950.22795468'   -- Return row_no 6 - this returns more than one
    17872962 '1.35364194.34880851'   -- Return row_no 4
    17872962 '2.23576950.22795468'   -- Return row_no 7
    22794978 '2.35364194.34889485'   -- Return row_no 1 - does not return anything
    22794978 '1.35364194.34889485'   -- Return row_no 1

    Hi,
    I'm not sure what you're asking.
    It would help if you posted the results you want as clearly as you posted the sample data. For each set of parametes, post the desired result set.
    I think you want to do two kinds of pattern matches, and return the results of the strictest one that has results.
    That is, if there is a match on all parts of structure_chain, then return the rows that match all parts.
    But if there is no match on all parts of structure_chain, then return the rows (if any) that match if we ignore the sub-atring before the first dot.
    That's an example of a Top-N Query , and here's one way to do it:
    WITH     got_r_num AS
         SELECT  tt.*
         ,     DENSE_RANK () OVER (ORDER BY  CASE
                                                WHEN  '&2'        LIKE structure_chain || '%'
                                    THEN  1
                                    ELSE  2
                                            END
                           ) AS r_num
         FROM     tt
         WHERE      old_child_id     = &1
         AND        SUBSTR ( '&2'
                     , INSTR ('&2', '.')
                     )                LIKE SUBSTR ( structure_chain
                                                  , INSTR (structure_chain, '.')
                                      ) || '%'
    SELECT     row_no, old_child_id, new_child_id, structure_chain
    FROM     got_r_num
    WHERE     r_num     = 1
    ;With parameters &1=17872962 and &2=1.23576950.22795468, the query above produces this output:
    `   ROW_NO OLD_CHILD_ID NEW_CHILD_ID STRUCTURE_CHAIN
             3     17872962     51755893 1.23576950
             6     17872962     51759248 1.23576950.22795468because both rows matched the given &2, including the '1.' at the beginning. (The query you posted gave the same results in this case.)
    With parameters &1=22794978 and &2=2.35364194.34889485, the query above produces:
        ROW_NO OLD_CHILD_ID NEW_CHILD_ID STRUCTURE_CHAIN
             1     22794978     51755902 1.35364194because there was no match when considering the '2.' at the beginning of &2, but the row shown does match when we ignore the '2.'.
    The WHERE clause in the sub-query narrows the result set down to rows that meet at least the looser match reuirement.
    The CASE expression ranks each row as 1 if it meets the stricter requirement, and 2 if it only met the looser one.
    DENSE_RANK returns 1 for the lower of those numbers that was actually found.

  • 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);

  • Trouble with OR in where clause

    Hello,
    I'm having trouble with execution speed. The problem seems to be with using OR in my where clause.
    Here's the meat of the function where i_pledge_number is an input parm:
    BEGIN
    SELECT /*+ INDEX (pp) */ SUM(pp.prim_pledge_amount)
    INTO return_amount
    FROM
    primary_pledge pp
    WHERE
    -- Get total if multiple allocations
    pp.prim_pledge_number IN
    (SELECT pc.pledge_number
    FROM pledge_codes pc
    WHERE pc.pledge_code_type = 'M'
    AND pc.pledge_code = 'AC'
    AND lpad(pc.pledge_comment,10,'0') = i_pledge_number)
    -- Get total if single allocation
    OR pp.prim_pledge_number = i_pledge_number;
    RETURN return_amount;
    END;
    If I comment out either half of the OR statement (either the subquery or the pp.prim_pledge_number = i_pledge_number half) the function returns a value in .02 seconds. If I leave the OR in, it takes 2.764 seconds to execute?? Can someone please show me a better way (faster) to do this? I tried using nvl() around the subquery but couldn't get it to compile.
    Thanks

    These things are difficult to diagnose remotely, but here is something you can try....
    SELECT */ SUM(pp.prim_pledge_amount)
    INTO return_amount
    FROM   primary_pledge pp
    WHERE  pp.prim_pledge_number IN (SELECT pc.pledge_number
                                     FROM pledge_codes pc
                                     WHERE pc.pledge_code_type = 'M'
                                     AND pc.pledge_code = 'AC'
                                     AND lpad(pc.pledge_comment,10,'0') = i_pledge_number
    UNION ALL
    SELECT i_pledge_number FROM dual)
       RETURN return_amount;
    END;If that doesn't do anything (and it might well not) there are a large number of different ways we can recast this query. To save us further guessing please give us more details: execution plans, database version number, volumetrics.
    Cheers, APC

  • VPD - How to make the where clause a correlated query

    Hi,
    My VPD function has the following where clause:
    where_clause:= ' project_id in (select object_id from pa_project_classes p'||
    ' where p.class_category='||''''||l_cat||''''||
    ' and p.CLASS_CODE='||''''||l_class||''''||
    ' and p.OBJECT_TYPE=''PA_PROJECTS'''||
    The problem is that the subquery is not using the unique key defined on the table pa_project_classes. What I need is something as follows:
    where_clause:= ' project_id in (select object_id from pa_project_classes p'||
    ' where p.class_category='||''''||l_cat||''''||
    ' and p.CLASS_CODE='||''''||l_class||''''||
    ' and p.OBJECT_TYPE=''PA_PROJECTS'''||
    ' and p.object_id=mainquery.project_id ||
    The problem is that since the table pa_project_classes also has a column project_id, I have to prefix the column name by the alias of the main query like 'mainquery.project_id'. However this seems impossible as main query is not unknown .
    I would be grateful if you could suggest any workaround or solution.
    Thanks

    Just have a look over these two statements if it solves your problem
    one time where clause
    Set_Block_Property('BLOCK_NAME',ONETIME_WHERE,your form item);
    dynamic where clause
    set_block_property('BLOCK_NAME'default_where, your form itme)
    you can where clause at run time from any procedure or some triggers

  • Using a WHERE clause in APEX Tree

    Hi All -
    I have an hierarchical SQL query that I'm displaying as an APEX tree.
    My sample app is here:
    https://apex.oracle.com/pls/apex/f?p=32581:29
    login: guest
    pw: app_1000
    workspace: leppard
    I am trying to add a WHERE clause so that only nodes with the lowest level children are displayed, i.e. something like 'WHERE connect_by_isleaf = 0 OR level = 5'
    The tree query with the where clause works fine in the SQL commands window, but when I add the WHERE clause to my apex tree the page no longer displays anything. Is this an issue with APEX or is there some other way to filter my results?
    Thanks in advance for any suggestions,
    john

    Connect by occurs first, the where clause then is applied to those results, effectively cutting away in the hierarchical structure. Since apex has to build a hierarchical structure from the query it relies on the level pseudocolumn, which is butchered by applying the where clause. It's a miracle you aren't even receiving errors because I'd almost expect an incorrect json array to have been built. With no top level to start from and only level 5 or leaf nodes there is no structure to present: both apex can not put out a correct representation and not jstree either. In your query you will see your "root nodes" but it is not representable.
    I'm not sure why you want to present this in a tree? Both connect_by_is_leaf and level = 5 will simply give you a list of nodes without any hierarchical structure.
    The better thing to do is to use a subquery to first limit your dataset and then use that to base the tree query on, that way you don't break any of those vital columns.
    Eg if you only want leaf nodes and their immediate parent you could go for something like this (quick mockup on some testdata):
    with dataset as (
    select node_id, parent_id
       from treedata
      where connect_by_isleaf = 0
    connect by prior node_id = parent_id
      start with parent_id = 0
    dataset2 as (
    select node_id, parent_id
      from dataset
    union all
    select node_id, null parent_id
      from treedata
    where node_id in (select parent_id from dataset)
    select level, node_id
       from dataset2
    connect by prior node_id = parent_id
      start with parent_id is null

  • Using collections in WHERE clause

    Hi friends,
    Please help me to use an associate array in SQL query (WHERE clause). The requirement is similar to the following example:
    ===============================================
    declare
    type rec_emp is record(emp_id integer, emp_name varchar2(100));
    type ty_emp is table of rec_emp index by pls_integer;
    tb_emp ty_emp;
    type ty_emp_history is table of emp_history%rowtype index by pls_integer;
    tb_emp_history ty_emp_history;
    begin
    select emp_id, emp_name
    bulk collect into tb_emp
    from emp
    where dept_id = 10;
    --Now I want to fetch records from emp_history based on the values in tb_emp. So I want a query something like the following.
    --(I know that join can be used to achive this. But it is just an example. I need to achive this in collections.)
    select *
    bulk collect into tb_emp_history
    from emp_history
    where emp_id = tb_emp.emp_id
    and emp_name = tb_emp.emp_name;
    end;
    ===============================================
    Thanks in advance.
    Edited by: Iniyavan on Oct 26, 2012 11:50 AM

    >
    Please help me to use an associate array in SQL query (WHERE clause).
    select *
    bulk collect into some_array
    >
    there is no variable 'some_array' in what you posted.
    If you want help with your code you have to post the code you are really using, not some hacked-up version of it that has errors.
    Here is sample code that shows how to treat a collection as a table using the TABLE operator
    -- type to match emp record
    create or replace type emp_scalar_type as object
      (EMPNO NUMBER(4) ,
       ENAME VARCHAR2(10),
       JOB VARCHAR2(9),
       MGR NUMBER(4),
       HIREDATE DATE,
       SAL NUMBER(7, 2),
       COMM NUMBER(7, 2),
       DEPTNO NUMBER(2)
    -- table of emp records
    create or replace type emp_table_type as table of emp_scalar_type
    declare
    tb emp_table_type;
    deptnoList sys.OdciNumberList;
    BEGIN
    select emp_scalar_type(empno, ename, job, mgr, hiredate, sal, comm, deptno)
    bulk collect into tb from emp;
    SELECT deptno bulk collect
    INTO deptnoList
    FROM dept where deptno not in (select deptno from table(tb));
    for i in 1..deptnoList.count loop
    dbms_output.put_Line(deptnoList(i));
    end loop;
    END;Note that tb is a collection and is useds in the subquery 'select deptno from table(tb)'.

  • How to use a function in a Where Clause?

    Hi,
    I've got a doubt. If MY_FUNCT is a function that returns a boolean, can I use it in a where clause for writing a query like this?:
    select ...
    from table a
    where ...
    and MY_FUNC (a.field) = true
    Thanks!
    Edited by: Mark1970 on 2-lug-2010 3.27

    Bear in mind that this could kill your performance.
    Depending on what you're doing, how many tables and other predicates are involved, you might want to try to eliminate all other data early before applying your function predicate otherwise your function might be called more times than you might have imagined. Strategies for this include subquery factoring and the old ROWNUM trick for materialising an inline view.
    If performance is impacted, you might also want to consider using a function-based index provided that the function is deterministic.

  • Sub query in where clause

    I have the following code which keeps throwing an error:
    select distinct game_code, count(player_id)
    from customer_data.cd_nhl_gm_tender_stats t
    where 
    (select distinct player_id
    from customer_data.cd_nhl_gm_tender_stats
    where season_id = 200818)
    group by game_code, player_id
    having count(player_id) > 1Error states that there's a missing expression right before the group by, any thoughts?
    The subquery is basically used to find a unique player_id value, (so there's no duplicates rows in the result set.)
    Sample data;
    customer_data.cd_nhl_gm_tender_stats t
    Game_code player_id
    88484           545454
    88484           545454
    88484           545454There's obviously other columns in the table above, but ultimatly there is mutliple rows for each game.
    I'm just trying to return each game_code where more then one player_id is found.

    Michaels2 i'm not sure your code is doing quite what i need
    select   *
      from   (select   t.*,
                       count (distinct player_id) over (partition by game_code) cnt
                from   cd_nhl_gm_tender_stats t where season_id = 200818)
    where   cnt > 1The subquery in the from clause is just selecting every game_code where season_id 200818 and then you add a where clause where cnt > 1 in the main query(whcih doesn't accomplish what I really wanted). What I need is the count of distinct player_id where season_id = 200818 AND cnt of (distinct player_id) over (partition by game_code) cnt > 2**. The issue i'm having is, that i'm not quite sure how to format the code to get these results.
    To clairfy what i need one more time ( i didn't explain things well in my original post)...
    I want each game_code where a player_id count is greather then two. And as stated earlier the gm_tender_stats table has numerous entries with the same player_id for the same_game code, which is why this makes writing this query a little more difficult.
    Edited by: user652714 on May 11, 2009 7:52 AM

  • Where clause in Data Block

    I'm running Forms 6i client/server.
    I have defined a where clause in the Property Palette for a Data Block.
    What I like to do is to extend the where clause with a subquery, but
    how can this be done? I mean, should I put the code in a trigger, which trigger?
    Regards
    Roar

    simple where clause with sub_query
    My block has name is dc_gmod. In the where pallete I put the text (and the all is work good!!!):
    exists
    select 1 from ttt.xxxxx_table v
    where (dc_gmod.cd_gmod = v.cd_gmod)
    and
    (instr(:fst.tmp_nm,cd_place,1) > 0
    or
    cd_place IN
    (select U_UNIT from ttt.xxxxxxxxx_tabe
    where RG_U = :QA.RG_UNIT_RUN
    AND SID = :QA.SID
    AND SERIAL# = :QA.SERIAL
    1.The dc_gmod.cd_gmod - is full name my block_name and item_name.
    2. The ttt.xxxxx_table is full name of my table what is source for block dc_gmod
    3. The cd_place is ITEM of BLOCK dc_gmod

Maybe you are looking for