Help me tune the sql query

Hi,
TKPROF: Release 8.1.7.0.0 - Production on Wed Sep 23 23:04:43 2009
(c) Copyright 2000 Oracle Corporation.  All rights reserved.
Trace file: pindb_ora_9943.trc
Sort options: prsela  exeela  fchela  fchela 
count    = number of times OCI procedure was executed
cpu      = cpu time in seconds executing
elapsed  = elapsed time in seconds executing
disk     = number of physical reads of buffers from disk
query    = number of buffers gotten for consistent read
current  = number of buffers gotten in current mode (usually for update)
rows     = number of rows processed by the fetch or execute call
SELECT f.poid_id0, COUNT (*), SUM (amount), d.subscription_amt, d.free_mb
FROM event_t a,
event_bal_impacts_t b,
(SELECT DISTINCT a.obj_id0 AS account_obj_id0, a.node_location,
a.plan_obj_id0
FROM account_products_t a
WHERE plan_obj_id0 > 0 AND service_obj_id0 > 0
UNION
SELECT DISTINCT a.account_obj_id0, a.node_location, a.plan_obj_id0
FROM audit_account_products_t a
WHERE plan_obj_id0 > 0
AND service_obj_id0 > 0
AND effective_end_t > 0) c,
iq_prov_tags_t d,
event_session_dialup_t e,
plan_t f
WHERE a.poid_id0 = b.obj_id0
AND a.poid_id0 = e.obj_id0
AND b.node_location = c.node_location
AND a.account_obj_id0 = c.account_obj_id0
AND c.plan_obj_id0 = d.plan_poid_id0
AND d.plan_poid_id0 = f.poid_id0
AND a.end_t >= pin_date_to_seconds (TRUNC (  SYSDATE
- 1), NULL)
AND a.end_t < pin_date_to_seconds (TRUNC (SYSDATE), NULL)
AND b.resource_id IN (1000051)
GROUP BY f.poid_id0, d.subscription_amt, d.free_mb
call     count       cpu    elapsed       disk      query    current        rows
Parse        1      0.09       0.08          0          0          0           0
Execute      2      0.07       0.07          0          0          0           0
Fetch        2    235.91    2295.25    1509704    1674184        346          11
total        5    236.07    2295.40    1509704    1674184        346          11
Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: 28 
Rows     Row Source Operation
     11  SORT GROUP BY
     69   NESTED LOOPS
     70    NESTED LOOPS
     70     NESTED LOOPS
     70      HASH JOIN
     70       HASH JOIN
300499        TABLE ACCESS BY INDEX ROWID EVENT_T
300500         INDEX RANGE SCAN (object id 26458)
816394        TABLE ACCESS BY INDEX ROWID EVENT_BAL_IMPACTS_T
816395         INDEX RANGE SCAN (object id 26463)
2385556       VIEW
2385556        SORT UNIQUE
3124105         UNION-ALL
638617          TABLE ACCESS FULL ACCOUNT_PRODUCTS_T
2485488          TABLE ACCESS FULL AUDIT_ACCOUNT_PRODUCTS_T
    138      TABLE ACCESS BY INDEX ROWID IQ_PROV_TAGS_T
    138       INDEX UNIQUE SCAN (object id 26554)
    138     INDEX UNIQUE SCAN (object id 23148)
     69    INDEX UNIQUE SCAN (object id 27372)
ALTER SESSION SET SQL_TRACE = TRUE
call     count       cpu    elapsed       disk      query    current        rows
Parse        0      0.00       0.00          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch        0      0.00       0.00          0          0          0           0
total        1      0.00       0.00          0          0          0           0
Misses in library cache during parse: 0
Misses in library cache during execute: 1
Optimizer goal: CHOOSE
Parsing user id: 28 
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
call     count       cpu    elapsed       disk      query    current        rows
Parse        1      0.09       0.08          0          0          0           0
Execute      3      0.07       0.07          0          0          0           0
Fetch        2    235.91    2295.25    1509704    1674184        346          11
total        6    236.07    2295.40    1509704    1674184        346          11
Misses in library cache during parse: 1
Misses in library cache during execute: 1
OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
call     count       cpu    elapsed       disk      query    current        rows
Parse        2      0.01       0.00          0          0          0           0
Execute      2      0.00       0.00          0          0          0           0
Fetch       20      0.00       0.01          0         40          0          18
total       24      0.01       0.01          0         40          0          18
Misses in library cache during parse: 1
    2  user  SQL statements in session.
    2  internal SQL statements in session.
    4  SQL statements in session.
Trace file: pindb_ora_9943.trc
Trace file compatibility: 8.00.04
Sort options: prsela  exeela  fchela  fchela 
       1  session in tracefile.
       2  user  SQL statements in trace file.
       2  internal SQL statements in trace file.
       4  SQL statements in trace file.
       3  unique SQL statements in trace file.
     118  lines in trace file.Inputs are appreciated
Prakash GR

sorry hash joint for asking this type of question but i do not have any option since i am not query tuner i need inputs so that i can put some effort on this
Would you like a cup of tea with this my dear ?chilled beer will be offered if any inputs given
Thanks
Prakash GR

Similar Messages

  • Need Help with Creating the SQl query

    Hi,
    SQL query gurus...
    INFORMATION:
    I have two table, CURRENT and PREVIOUS.(Table Defs below).
    CURRENT:
    Column1 - CURR_PARENT
    Column2 - CURR_CHILD
    Column3 - CURR_CHILD_ATTRIBUTE 1
    Column4 - CURR_CHILD_ATTRIBUTE 2
    Column5 - CURR_CHILD_ATTRIBUTE 3
    PREVIOUS:
    Column1 - PREV_PARENT
    Column2 - PREV_CHILD
    Column3 - PREV_CHILD_ATTRIBUTE 1
    Column4 - PREV_CHILD_ATTRIBUTE 2
    Column5 - PREV_CHILD_ATTRIBUTE 3
    PROBLEM STATEMENT
    Here the columns 3 to 5 are the attributes of the Child. Lets assume that I have two loads, One Today which goes to the CURRENT table and one yesterday which goes to the PREVIOUS table. Between these two loads there is a CHANGE in the value for Columns either 3/4/5 or all of them(doesnt matter if one or all).
    I want to determine what properties for the child have changed with the help of a MOST efficient SQL query.(PARENT+CHILD is unique key). The Database is ofcourse ORACLE.
    Please help.
    Regards,
    Parag

    Hi,
    The last message was not posted by the same user_name that started the thread.
    Please don't do that: it's confusing.
    Earlier replies give you the information you want, with one row of output (maximum) per row in current_tbl. There may be 1, 2 or 3 changes on a row.
    You just have to unpivot that data to get one row for every change, like this:
    WITH     single_row  AS
         SELECT     c.curr_parent
         ,     c.curr_child
         ,     c.curr_child_attribute1
         ,     c.curr_child_attribute2
         ,     c.curr_child_attribute3
         ,     DECODE (c.curr_child_attribute1, p.prev_child_attribute1, 0, 1) AS diff1
         ,     DECODE (c.curr_child_attribute2, p.prev_child_attribute2, 0, 2) AS diff2
         ,     DECODE (c.curr_child_attribute3, p.prev_child_attribute3, 0, 3) AS diff3
         FROM     current_tbl    c
         JOIN     previous_tbl   p     ON  c.curr_parent     = p.prev_parent
                                AND c.curr_child     = p.prev_child
         WHERE     c.curr_child_attribute1     != p.prev_child_attribute1
         OR     c.curr_child_attribute2     != p.prev_child_attribute2
         OR     c.curr_child_attribute3     != p.prev_child_attribute3
    ,     cntr     AS
         SELECT     LEVEL     AS n
         FROM     dual
         CONNECT BY     LEVEL <= 3
    SELECT     s.curr_parent     AS parent
    ,     s.curr_child     AS child
    ,     CASE     c.n
              WHEN  1  THEN  s.curr_child_attribute1
              WHEN  2  THEN  s.curr_child_attribute2
              WHEN  3  THEN  s.curr_child_attribute3
         END          AS attribute
    ,     c.n          AS attribute_value
    FROM     single_row     s
    JOIN     cntr          c     ON     c.n IN ( s.diff1
                                    , s.diff2
                                    , s.diff3
    ORDER BY  attribute_value
    ,            parent
    ,            child
    ;

  • Need to tune the sql query

    Hi,
    PLease help me to tune the query
    select primary_rep,
    rep_ssn,
    nvl(product_type_desc, 'UNKNOWN') as productName,
    ROUND(sum(contributions)) as contribution,
    ROUND(sum(withdrawls)) as withdrawls,
    ROUND(sum(netflow)) as netflow
    from dev.NETFLOW_VIEW_TSS_P
    where bd = 'TSS'
    and actvtydate between '01-Jan-2011' and '30-Sep-2011'     
    and rep_ssn IN (select tax_id from broker_view where broker_id = '600468')
    group by primary_rep, rep_ssn, nvl(product_type_desc, 'UNKNOWN');
    explain plan details below
    | Id  | Operation                                     | Name                        | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT                              |                             |    79 |   158K|       | 74348   (1)| 00:14:53 |       |       |
    |   1 |  HASH GROUP BY                                |                             |    79 |   158K|       | 74348   (1)| 00:14:53 |       |       |
    |*  2 |   HASH JOIN                                   |                             |    79 |   158K|       | 74347   (1)| 00:14:53 |       |       |
    |   3 |    VIEW                                       | VW_NSO_1                    |     1 |     6 |       |    18  (17)| 00:00:01 |       |       |
    |   4 |     HASH UNIQUE                               |                             |     1 |   100 |       |    18  (17)| 00:00:01 |       |       |
    |   5 |      NESTED LOOPS OUTER                       |                             |     1 |   100 |       |    17  (12)| 00:00:01 |       |       |
    |   6 |       MERGE JOIN CARTESIAN                    |                             |     1 |    92 |       |    17  (12)| 00:00:01 |       |       |
    |   7 |        NESTED LOOPS OUTER                     |                             |     1 |    71 |       |    15  (14)| 00:00:01 |       |       |
    |   8 |         NESTED LOOPS OUTER                    |                             |     1 |    67 |       |    12  (17)| 00:00:01 |       |       |
    |*  9 |          HASH JOIN OUTER                      |                             |     1 |    63 |       |    10  (20)| 00:00:01 |       |       |
    |  10 |           NESTED LOOPS OUTER                  |                             |     1 |    56 |       |     6   (0)| 00:00:01 |       |       |
    |  11 |            NESTED LOOPS OUTER                 |                             |     1 |    52 |       |     4   (0)| 00:00:01 |       |       |
    |  12 |             TABLE ACCESS BY INDEX ROWID       | AFFILIATE                   |     1 |    45 |       |     2   (0)| 00:00:01 |       |       |
    |* 13 |              INDEX UNIQUE SCAN                | AFFILIATE_PK                |     1 |       |       |     1   (0)| 00:00:01 |       |       |
    |* 14 |             TABLE ACCESS FULL                 | PORTAL_BROKER               |     1 |     7 |       |     2   (0)| 00:00:01 |       |       |
    |  15 |            VIEW PUSHED PREDICATE              |                             |     1 |     4 |       |     2   (0)| 00:00:01 |       |       |
    |  16 |             NESTED LOOPS                      |                             |     1 |    28 |       |     2   (0)| 00:00:01 |       |       |
    |  17 |              NESTED LOOPS                     |                             |     1 |    21 |       |     2   (0)| 00:00:01 |       |       |
    |* 18 |               TABLE ACCESS BY INDEX ROWID     | LOCATION_GROUP_TYPE_DESC    |     1 |     5 |       |     1   (0)| 00:00:01 |       |       |
    |* 19 |                INDEX UNIQUE SCAN              | LOCATION_GROUP_TYPE_DESC_PK |     1 |       |       |     0   (0)| 00:00:01 |       |       |
    |* 20 |               INDEX RANGE SCAN                | LOCATION_GROUP_UK           |     1 |    16 |       |     1   (0)| 00:00:01 |       |       |
    |* 21 |              INDEX UNIQUE SCAN                | CONTACT_METHOD_PK           |     1 |     7 |       |     0   (0)| 00:00:01 |       |       |
    |  22 |           VIEW                                |                             |     1 |     7 |       |     3  (34)| 00:00:01 |       |       |
    |  23 |            HASH UNIQUE                        |                             |     1 |    11 |       |     3  (34)| 00:00:01 |       |       |
    |* 24 |             INDEX RANGE SCAN                  | AFFILIATE_TYPE_PK           |     1 |    11 |       |     2   (0)| 00:00:01 |       |       |
    |  25 |          VIEW PUSHED PREDICATE                |                             |     1 |     4 |       |     2   (0)| 00:00:01 |       |       |
    |  26 |           NESTED LOOPS                        |                             |     1 |    28 |       |     2   (0)| 00:00:01 |       |       |
    |  27 |            NESTED LOOPS                       |                             |     1 |    21 |       |     2   (0)| 00:00:01 |       |       |
    |* 28 |             TABLE ACCESS BY INDEX ROWID       | LOCATION_GROUP_TYPE_DESC    |     1 |     5 |       |     1   (0)| 00:00:01 |       |       |
    |* 29 |              INDEX UNIQUE SCAN                | LOCATION_GROUP_TYPE_DESC_PK |     1 |       |       |     0   (0)| 00:00:01 |       |       |
    |* 30 |             INDEX RANGE SCAN                  | LOCATION_GROUP_UK           |     1 |    16 |       |     1   (0)| 00:00:01 |       |       |
    |* 31 |            INDEX UNIQUE SCAN                  | CONTACT_METHOD_PK           |     1 |     7 |       |     0   (0)| 00:00:01 |       |       |
    |  32 |         VIEW PUSHED PREDICATE                 |                             |     1 |     4 |       |     3   (0)| 00:00:01 |       |       |
    |  33 |          NESTED LOOPS OUTER                   |                             |     1 |    35 |       |     3   (0)| 00:00:01 |       |       |
    |  34 |           NESTED LOOPS                        |                             |     1 |    32 |       |     3   (0)| 00:00:01 |       |       |
    |  35 |            NESTED LOOPS                       |                             |     1 |    22 |       |     2   (0)| 00:00:01 |       |       |
    |* 36 |             TABLE ACCESS BY INDEX ROWID       | LOCATION_GROUP_TYPE_DESC    |     1 |     5 |       |     1   (0)| 00:00:01 |       |       |
    |* 37 |              INDEX UNIQUE SCAN                | LOCATION_GROUP_TYPE_DESC_PK |     1 |       |       |     0   (0)| 00:00:01 |       |       |
    |* 38 |             INDEX RANGE SCAN                  | LOCATION_GROUP_UK           |     1 |    17 |       |     1   (0)| 00:00:01 |       |       |
    |  39 |            TABLE ACCESS BY INDEX ROWID        | ADDRESS                     |     1 |    10 |       |     1   (0)| 00:00:01 |       |       |
    |* 40 |             INDEX UNIQUE SCAN                 | ADDRESS_PK                  |     1 |       |       |     0   (0)| 00:00:01 |       |       |
    |* 41 |           INDEX UNIQUE SCAN                   | PROV_STDSC_PK               |     1 |     3 |       |     0   (0)| 00:00:01 |       |       |
    |  42 |        BUFFER SORT                            |                             |     1 |    21 |       |    14  (15)| 00:00:01 |       |       |
    |* 43 |         INDEX RANGE SCAN                      | I_BROKER_BKBRCMB            |     1 |    21 |       |     2   (0)| 00:00:01 |       |       |
    |* 44 |       INDEX UNIQUE SCAN                       | BROKER_BRANCH_PK            |     1 |     8 |       |     0   (0)| 00:00:01 |       |       |
    |  45 |    VIEW                                       | NETFLOW_VIEW_TSS_P          |   391K|   766M|       | 74325   (1)| 00:14:52 |       |       |
    |  46 |     UNION-ALL                                 |                             |       |       |       |            |          |       |       |
    |* 47 |      HASH JOIN RIGHT OUTER                    |                             | 11645 |  1671K|       | 49023   (1)| 00:09:49 |       |       |
    |  48 |       VIEW                                    |                             |     1 |    38 |       | 13602   (1)| 00:02:44 |       |       |
    |* 49 |        FILTER                                 |                             |       |       |       |            |          |       |       |
    |  50 |         TABLE ACCESS FULL                     | SALES_REPORT_REP_MAPPING    |  9023 |   326K|       |    58   (2)| 00:00:01 |       |       |
    |* 51 |         FILTER                                |                             |       |       |       |            |          |       |       |
    |  52 |          SORT GROUP BY NOSORT                 |                             |     1 |    11 |       |     3   (0)| 00:00:01 |       |       |
    |  53 |           TABLE ACCESS BY INDEX ROWID         | SALES_REPORT_REP_MAPPING    |     1 |    11 |       |     3   (0)| 00:00:01 |       |       |
    |* 54 |            INDEX RANGE SCAN                   | I_SAL_REP_MAP_REPID         |     1 |       |       |     2   (0)| 00:00:01 |       |       |
    |  55 |       NESTED LOOPS                            |                             | 11645 |  1239K|       | 35420   (1)| 00:07:06 |       |       |
    |* 56 |        HASH JOIN RIGHT OUTER                  |                             | 11645 |   898K|       | 12112   (1)| 00:02:26 |       |       |
    |  57 |         INDEX FAST FULL SCAN                  | I_VENDORS_ACCTLOC           |   986 |  3944 |       |     2   (0)| 00:00:01 |       |       |
    |* 58 |         HASH JOIN RIGHT OUTER                 |                             | 11645 |   852K|       | 12109   (1)| 00:02:26 |       |       |
    |* 59 |          MAT_VIEW ACCESS FULL                 | SECS_DESC                   | 26777 |   418K|       |  3082   (1)| 00:00:37 |       |       |
    |* 60 |          FILTER                               |                             |       |       |       |            |          |       |       |
    |* 61 |           HASH JOIN RIGHT OUTER               |                             | 11645 |   670K|       |  9026   (1)| 00:01:49 |       |       |
    |  62 |            MAT_VIEW ACCESS FULL               | ENTRYCODES                  |  1640 | 11480 |       |     8   (0)| 00:00:01 |       |       |
    |* 63 |            HASH JOIN                          |                             | 34936 |  1774K|       |  9017   (1)| 00:01:49 |       |       |
    |* 64 |             INDEX FULL SCAN                   | I_CODE                      |    30 |   420 |       |     1   (0)| 00:00:01 |       |       |
    |  65 |             PARTITION RANGE ALL               |                             |   342K|    12M|       |  9013   (1)| 00:01:49 |     1 |    20 |
    |  66 |              TABLE ACCESS BY LOCAL INDEX ROWID| BKPG                        |   342K|    12M|       |  9013   (1)| 00:01:49 |     1 |    20 |
    |* 67 |               INDEX RANGE SCAN                | I_BKPG_ACT_REC_IDX          |   342K|       |       |  1412   (1)| 00:00:17 |     1 |    20 |
    |  68 |        TABLE ACCESS BY INDEX ROWID            | ACCT_CUBE                   |     1 |    30 |       |     2   (0)| 00:00:01 |       |       |
    |* 69 |         INDEX UNIQUE SCAN                     | ACCT_CUBE_PK                |     1 |       |       |     1   (0)| 00:00:01 |       |       |
    |* 70 |      HASH JOIN RIGHT OUTER                    |                             |   379K|    52M|       | 25303   (1)| 00:05:04 |       |       |
    |  71 |       VIEW                                    |                             |     1 |    38 |       | 13602   (1)| 00:02:44 |       |       |
    |* 72 |        FILTER                                 |                             |       |       |       |            |          |       |       |
    |  73 |         TABLE ACCESS FULL                     | SALES_REPORT_REP_MAPPING    |  9023 |   326K|       |    58   (2)| 00:00:01 |       |       |
    |* 74 |         FILTER                                |                             |       |       |       |            |          |       |       |
    |  75 |          SORT GROUP BY NOSORT                 |                             |     1 |    11 |       |     3   (0)| 00:00:01 |       |       |
    |  76 |           TABLE ACCESS BY INDEX ROWID         | SALES_REPORT_REP_MAPPING    |     1 |    11 |       |     3   (0)| 00:00:01 |       |       |
    |* 77 |            INDEX RANGE SCAN                   | I_SAL_REP_MAP_REPID         |     1 |       |       |     2   (0)| 00:00:01 |       |       |
    |* 78 |       HASH JOIN                               |                             |   379K|    39M|    33M| 11696   (2)| 00:02:21 |       |       |
    |* 79 |        HASH JOIN                              |                             |   379K|    28M|       |  3210   (2)| 00:00:39 |       |       |
    |* 80 |         INDEX FAST FULL SCAN                  | I_VENDORS_ACCTLOC           |   986 |  3944 |       |     2   (0)| 00:00:01 |       |       |
    |* 81 |         HASH JOIN                             |                             |   379K|    27M|    14M|  3204   (2)| 00:00:39 |       |       |
    |  82 |          INDEX FAST FULL SCAN                 | SECS_DESC_PK                |   744K|  6545K|       |   457   (3)| 00:00:06 |       |       |
    |* 83 |          FILTER                               |                             |       |       |       |            |          |       |       |
    |* 84 |           HASH JOIN RIGHT OUTER               |                             |   379K|    24M|       |   569   (3)| 00:00:07 |       |       |
    |  85 |            MAT_VIEW ACCESS FULL               | MFENTRYCODES                |  6853 | 61677 |       |    15   (0)| 00:00:01 |       |       |
    |  86 |            PARTITION RANGE ALL                |                             |  1138K|    62M|       |   542   (1)| 00:00:07 |     1 |    15 |
    |* 87 |             TABLE ACCESS BY LOCAL INDEX ROWID | MFBKPG                      |  1138K|    62M|       |   542   (1)| 00:00:07 |     1 |    15 |
    |* 88 |              INDEX RANGE SCAN                 | I_MFBKPGP_ACTDT_ACCT_TST    |   904 |       |       |   107   (0)| 00:00:02 |     1 |    15 |
    |  89 |        INDEX FAST FULL SCAN                   | I_ACCT_CUBE_REPID_MKT       |  1952K|    52M|       |  3096   (2)| 00:00:38 |       |       |
    Predicate Information (identified by operation id):
       2 - access("REP_SSN"="$nso_col_1")
       9 - access("A"."AFFILIATE_ID"="MGR"."AFFILIATE_ID"(+))
      13 - access("A"."AFFILIATE_ID"='600468')
      14 - filter("PORTAL_BROKER"."BROKER_ID"(+)='600468')
      18 - filter("LT"."ADDRESS_CONTACT_IND"='C')
      19 - access("LT"."LOCATION_GROUP_TYPE_CODE"='WF')
      20 - access("L"."LOCATION_GROUP_TYPE_CODE"='WF' AND "L"."AFFILIATE_ID"="A"."AFFILIATE_ID")
           filter("L"."CONTACT_METHOD_ID" IS NOT NULL)
      21 - access("L"."CONTACT_METHOD_ID"="B"."CONTACT_METHOD_ID")
      24 - access("AFFILIATE_ID"='600468')
           filter("AFFILIATE_TYPE"='BBE' OR "AFFILIATE_TYPE"='BRM' OR "AFFILIATE_TYPE"='ISP')
      28 - filter("LT"."ADDRESS_CONTACT_IND"='C')
      29 - access("LT"."LOCATION_GROUP_TYPE_CODE"='WT')
      30 - access("L"."LOCATION_GROUP_TYPE_CODE"='WT' AND "L"."AFFILIATE_ID"="A"."AFFILIATE_ID")
           filter("L"."CONTACT_METHOD_ID" IS NOT NULL)
      31 - access("L"."CONTACT_METHOD_ID"="B"."CONTACT_METHOD_ID")
      36 - filter("LT"."ADDRESS_CONTACT_IND"='A')
      37 - access("LT"."LOCATION_GROUP_TYPE_CODE"='WM')
      38 - access("L"."LOCATION_GROUP_TYPE_CODE"='WM' AND "L"."AFFILIATE_ID"="A"."AFFILIATE_ID")
           filter("L"."ADDRESS_ID" IS NOT NULL)
      40 - access("L"."ADDRESS_ID"="A"."ADDRESS_ID")
      41 - access("A"."PROVINCE_STATE_CODE"="S"."PROVINCE_STATE_CODE"(+))
      43 - access("B"."BROKER_ID"='600468')
      44 - access("B"."BRANCH_ID"="BR"."BRANCH_ID"(+))
      47 - access("B"."REPID"="K"."REPID"(+))
      49 - filter( EXISTS (SELECT 0 FROM DEV."SALES_REPORT_REP_MAPPING" "SALES_REPORT_REP_MAPPING" WHERE "REPID"=:B1 GROUP BY "REPID" HAVING
                  SUM(NVL("PCT",100))=100))
      51 - filter(SUM(NVL("PCT",100))=100)
      54 - access("REPID"=:B1)
      56 - access(NVL("V"."VENDOR_CD"(+),'xxx')=NVL("VENDOR_CD",'yyy'))
      58 - access("CUSIP"(+)="A"."CUSIP")
      59 - filter("COMM_SECTYPE"(+)='MF')
      60 - filter(NVL("Z"."PERF_INCLUDE_PORTFOLIO",'xx')='Y')
      61 - access("A"."ENTRYCODE"="Z"."ENTRYCODE"(+))
      63 - access("CODE_IN"=SUBSTR("A"."ACCT",1,3))
      64 - access("CODE_TYPE"='NETFLOW')
           filter("CODE_TYPE"='NETFLOW')
      67 - access("A"."ACTVTYDATE">=TO_DATE(' 2011-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "A"."ACTVTYDATE"<=TO_DATE(' 2011-09-30
                  00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
      69 - access("B"."ACCOUNTKEY"='11,,,'||"A"."ACCT")
      70 - access("A"."REPID"="K"."REPID"(+))
      72 - filter( EXISTS (SELECT 0 FROM DEV."SALES_REPORT_REP_MAPPING" "SALES_REPORT_REP_MAPPING" WHERE "REPID"=:B1 GROUP BY "REPID" HAVING
                  SUM(NVL("PCT",100))=100))
      74 - filter(SUM(NVL("PCT",100))=100)
      77 - access("REPID"=:B1)
      78 - access("A"."ACCOUNTKEY"='20,'||"B"."VENDOR_CD"||','||"B"."FUNDNO"||','||"B"."ACCT")
      79 - access("V"."VENDOR_CD"="B"."VENDOR_CD")
      80 - filter("V"."VENDOR_CD"<>'HNR' AND "V"."VENDOR_CD"<>'CNL' AND "V"."VENDOR_CD"<>'IRE' AND "V"."VENDOR_CD"<>'WLR' AND
                  "V"."VENDOR_CD"<>'WLP' AND "V"."VENDOR_CD"<>'PER' AND "V"."VENDOR_CD"<>'BHV')
      81 - access("SD"."CUSIP"="B"."CUSIP")
      83 - filter(NVL("E"."PERF_INCLUDE_PORTFOLIO",'xx')='Y')
      84 - access("B"."ENTRYCODE"="E"."ENTRYCODE"(+))
      87 - filter("B"."VENDOR_CD"<>'HNR' AND "B"."VENDOR_CD"<>'CNL' AND "B"."VENDOR_CD"<>'IRE' AND "B"."VENDOR_CD"<>'WLR' AND
                  "B"."VENDOR_CD"<>'WLP' AND "B"."VENDOR_CD"<>'PER' AND "B"."VENDOR_CD"<>'BHV')
      88 - access(SYS_OP_DESCEND("ACTVTYDATE")>=HEXTORAW('8790F6E1FEF8FEFAFF')  AND SYS_OP_DESCEND("ACTVTYDATE")<=HEXTORAW('8790FEF8FEF8FEFAFF')
           filter(SYS_OP_UNDESCEND(SYS_OP_DESCEND("ACTVTYDATE"))>=TO_DATE(' 2011-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
                  SYS_OP_UNDESCEND(SYS_OP_DESCEND("ACTVTYDATE"))<=TO_DATE(' 2011-09-30 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
    158 rows selected.Thanks

    So this is a VIEW with I think 18 tables (I may have missed one or two), some of which are referenced more than one. Some of these tables have tens of miilions of rows. What exactly are you expecting from us?
    I guess this is a data warehouse or BI query. Sometimes such queries just take an age to run and there's nothing which can be done except result caching. Other times the queries can be tuned, but iit requires way more context and domain knowledge than you have provided.
    Please start by reading [url https://forums.oracle.com/forums/thread.jspa?threadID=2174552#9360003]this FAQ. .
    Cheers, APC

  • Request for tunning the SQL query

    Hi,
    I've a query mentioned below.I've tried it in different ways.But still it is taking much time.
    And there are some 9 indexes created on the column siteid. And both the table having indexes.But still full table scanning occuring for both the tables. Can any one help on this.Or can anyone write the same query in a different way.
    select r.recordkey,
         r.orgid,
         r.siteid,
         r.class,
    w.pscdate,
         w.ascdate,
         w.targstartdate,
         w.targcompdate,
         w.schedfinish,
         w.actfinish,
         w.estdur,
         w.wonum,
         w.mprn,
    w.sihousename wositehousename,
         w.sihouseno wositehouseno,
         w.sistreet wositestreet,
    w.sicounty wositecounty,
         w.siposttown wositeposttown,
         w.sipostcode wositepostcode,
    w.workorderid
    from relatedrecord r,
    workorder w
    where r.relatedreckey = case when w.parent is null then w.wonum else w.parent end
    and r.orgid = w.orgid
    and r.siteid = w.siteid
    and r.relatedrecclass = 'WORKORDER'
    Explain Plan Res:
    Operation     Object Name     Rows     Bytes     Cost     Object Node     In/Out     PStart     PStop
    SELECT STATEMENT Optimizer Mode=ALL_ROWS          38 K          4819                     
    HASH JOIN          38 K     5 M     4819                     
    TABLE ACCESS FULL     MAXIMO.RELATEDRECORD     30 K     1 M     390                     
    TABLE ACCESS FULL     MAXIMO.WORKORDER     229 K     26 M     2922                     
    Regards,
    Arjun.

    Hi,
    Some question.
    1) r.relatedrecclass = 'WORKORDER', how many records are there with relatedrecclass as "WORKORDER" compared to the total number of records in that table (in percentage)
    2) Do we have index on relatedrecclass? (if possible in combination with recordkey and class column)
    3) What is the total number of records in both the table?
    4) What is the expected number of records with the below query?
    Regards
    Anurag

  • Tune the SQL Query need a Suggestion

    Hi,
    There is a view created which takes 17seconds to execute the query, When i split the query and execute each query takes .15 seconds to execute. Below it the query which i need to improve the performance of the code please need your suggestion in order to tweek so that time take for execution become less
    SELECT 'Parature' "Source",
    NULL "Distibutor",
    reseller_name "Reseller",
    NULL "Reseller City",
    NULL "Reseller State",
    A.Country "Reseller Country",
    DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
    NULL "Customer Name",
    NULL "Customer City",
    NULL "Customer State",
    NULL "Customer Country",
    NULL "Customer Theater",
    NULL "Sales Book Date",
    NULL "Ship Date",
    c.sales_order_number "Sales Order Number",
    C.Po_Number "PO Number",
    controller_model_number_1 "Product Name",
    TRIM (UPPER (serial_number_1)) "Product Serial Number",
    c.contract_id "Contract ID",
    product_name "Support Name",
    TO_DATE (c.contract_purchase_date) "Start Date",
    TO_DATE (c.contract_expiration_date) "Expire Date",
    NULL "Header Status",
    NULL "Line Status",
    NULL "Line Type",
    NULL "Termination Reason",
    NULL "Location_id",
    NULL "Product_id"
    FROM edb_assets c,
    edb_accounts a
    WHERE controller_model_number_1 != 'NULL'
    AND Serial_Number_1 != 'NULL'
    AND C.Amid = A.Amid(+)
    UNION
    SELECT 'Parature' "Source",
    NULL "Distibutor",
    reseller_name "Reseller",
    NULL "Reseller City",
    NULL "Reseller State",
    A.Country "Reseller Country",
    DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
    NULL "Customer Name",
    NULL "Customer City",
    NULL "Customer State",
    NULL "Customer Country",
    NULL "Customer Theater",
    NULL "Sales Book Date",
    NULL "Ship Date",
    c.sales_order_number "Sales Order Number",
    C.Po_Number "PO Number",
    controller_model_number_2 "Product Name",
    TRIM (UPPER (serial_number_2)) "Product Serial Number",
    c.contract_id "Contract ID",
    product_name "Support Name",
    TO_DATE (c.contract_purchase_date) "Start Date",
    TO_DATE (c.contract_expiration_date) "Expire Date",
    NULL "Header Status",
    NULL "Line Status",
    NULL "Line Type",
    NULL "Termination Reason",
    NULL "Location_id",
    NULL "Product_id"
    FROM edb_assets c,
    edb_accounts a
    WHERE controller_model_number_2 != 'NULL'
    AND serial_number_2 != 'NULL'
    AND C.Amid = A.Amid(+)
    UNION
    SELECT 'Parature' "Source",
    NULL "Distibutor",
    reseller_name "Reseller",
    NULL "Reseller City",
    NULL "Reseller State",
    A.Country "Reseller Country",
    DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
    NULL "Customer Name",
    NULL "Customer City",
    NULL "Customer State",
    NULL "Customer Country",
    NULL "Customer Theater",
    NULL "Sales Book Date",
    NULL "Ship Date",
    c.sales_order_number "Sales Order Number",
    C.Po_Number "PO Number",
    controller_model_number_3 "Product Name",
    TRIM (UPPER (serial_number_3)) "Product Serial Number",
    c.contract_id "Contract ID",
    product_name "Support Name",
    TO_DATE (c.contract_purchase_date) "Start Date",
    TO_DATE (c.contract_expiration_date) "Expire Date",
    NULL "Header Status",
    NULL "Line Status",
    NULL "Line Type",
    NULL "Termination Reason",
    NULL "Location_id",
    NULL "Product_id"
    FROM edb_assets c,
    edb_accounts a
    WHERE controller_model_number_3 != 'NULL'
    AND serial_number_3 != 'NULL'
    AND C.Amid = A.Amid(+)
    UNION
    SELECT 'Parature' "Source",
    NULL "Distibutor",
    reseller_name "Reseller",
    NULL "Reseller City",
    NULL "Reseller State",
    A.Country "Reseller Country",
    DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
    NULL "Customer Name",
    NULL "Customer City",
    NULL "Customer State",
    NULL "Customer Country",
    NULL "Customer Theater",
    NULL "Sales Book Date",
    NULL "Ship Date",
    c.sales_order_number "Sales Order Number",
    C.Po_Number "PO Number",
    controller_model_number_4 "Product Name",
    TRIM (UPPER (serial_number_4)) "Product Serial Number",
    c.contract_id "Contract ID",
    product_name "Support Name",
    TO_DATE (c.contract_purchase_date) "Start Date",
    TO_DATE (c.contract_expiration_date) "Expire Date",
    NULL "Header Status",
    NULL "Line Status",
    NULL "Line Type",
    NULL "Termination Reason",
    NULL "Location_id",
    NULL "Product_id"
    FROM edb_assets c,
    edb_accounts a
    WHERE controller_model_number_4 != 'NULL'
    AND serial_number_4 != 'NULL'
    AND C.Amid = A.Amid(+)
    UNION
    SELECT 'Parature' "Source",
    NULL "Distibutor",
    reseller_name "Reseller",
    NULL "Reseller City",
    NULL "Reseller State",
    A.Country "Reseller Country",
    DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
    NULL "Customer Name",
    NULL "Customer City",
    NULL "Customer State",
    NULL "Customer Country",
    NULL "Customer Theater",
    NULL "Sales Book Date",
    NULL "Ship Date",
    c.sales_order_number "Sales Order Number",
    C.Po_Number "PO Number",
    controller_model_number_5 "Product Name",
    TRIM (UPPER (serial_number_5)) "Product Serial Number",
    c.contract_id "Contract ID",
    product_name "Support Name",
    TO_DATE (c.contract_purchase_date) "Start Date",
    TO_DATE (c.contract_expiration_date) "Expire Date",
    NULL "Header Status",
    NULL "Line Status",
    NULL "Line Type",
    NULL "Termination Reason",
    NULL "Location_id",
    NULL "Product_id"
    FROM edb_assets c,
    edb_accounts a
    WHERE controller_model_number_5 != 'NULL'
    AND serial_number_5 != 'NULL'
    AND C.Amid = A.Amid(+)
    UNION
    SELECT 'ERP' "Source",
    Imv.Bill_To "Distibutor",
    Imv.Ship_To "Reseller",
    Ship_To_City "Reseller City",
    Ship_To_State "Reseller State",
    Edb2_Global.Country_Name_Theater(Imv.Ship_To_Country ,'COUNTRY') "Reseller Country",
    Edb2_Global.Country_Name_Theater(Imv.Ship_To_Country ,'THEATER') "Reseller Theater",
    Cl.Company_Name "Customer Name",
    Cl.City "Customer City",
    Cl.State "Customer State",
    Edb2_Global.Country_Name_Theater(Cl.Country,'COUNTRY') "Customer Country",
    Edb2_Global.Country_Name_Theater(Cl.Country,'THEATER') "Customer Theater",
    Imv.So_Booked_Date "Sales Book Date",
    Imv.Ship_Date "Ship Date",
    Imv.Order_Number "Sales Order Number",
    Imv.Cust_Po_Number "PO Number",
    Cp.Item_Name "Product Name",
    Cp.Product_Serial_Number "Product Serial Number",
    TO_CHAR(Imv.contract_number)"Contract ID",
    Imv.Service_Description "Support Name",
    Imv.Service_Start_Date "Start Date",
    Imv.Service_End_Date "Expire Date",
    Imv.Header_Status "Header Status",
    Imv.Line_Status "Line Status",
    Imv.Line_Type "Line Type",
    Imv.Termination_Reason "Termination Reason",
    Cl.Location_Id "Location_id",
    cp.id "Product_id"
    FROM ib_support_contracts_mv imv,
    customer_products cp,
    customer_locations cl
    WHERE Upper (Trim (Imv.Serial_Number)) = Upper (Trim (Cp.Product_Serial_Number(+)))
    AND Cp.Location_Id = Cl.Location_Id(+)
    There is a union for each and every query, Please suggest how to tweek
    Thanks
    Sudhir

    Try
    select distinct a.*
    from (SELECT 'Parature' "Source",
    NULL "Distibutor",
    reseller_name "Reseller",
    NULL "Reseller City",
    NULL "Reseller State",
    A.Country "Reseller Country",
    DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
    NULL "Customer Name",
    NULL "Customer City",
    NULL "Customer State",
    NULL "Customer Country",
    NULL "Customer Theater",
    NULL "Sales Book Date",
    NULL "Ship Date",
    c.sales_order_number "Sales Order Number",
    C.Po_Number "PO Number",
    controller_model_number_1 "Product Name",
    TRIM (UPPER (serial_number_1)) "Product Serial Number",
    c.contract_id "Contract ID",
    product_name "Support Name",
    TO_DATE (c.contract_purchase_date) "Start Date",
    TO_DATE (c.contract_expiration_date) "Expire Date",
    NULL "Header Status",
    NULL "Line Status",
    NULL "Line Type",
    NULL "Termination Reason",
    NULL "Location_id",
    NULL "Product_id"
    FROM edb_assets c,
    edb_accounts a
    WHERE controller_model_number_1 != 'NULL'
    AND Serial_Number_1 != 'NULL'
    AND C.Amid = A.Amid(+)
    union all
    SELECT 'Parature' "Source",
    NULL "Distibutor",
    reseller_name "Reseller",
    NULL "Reseller City",
    NULL "Reseller State",
    A.Country "Reseller Country",
    DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
    NULL "Customer Name",
    NULL "Customer City",
    NULL "Customer State",
    NULL "Customer Country",
    NULL "Customer Theater",
    NULL "Sales Book Date",
    NULL "Ship Date",
    c.sales_order_number "Sales Order Number",
    C.Po_Number "PO Number",
    controller_model_number_2 "Product Name",
    TRIM (UPPER (serial_number_2)) "Product Serial Number",
    c.contract_id "Contract ID",
    product_name "Support Name",
    TO_DATE (c.contract_purchase_date) "Start Date",
    TO_DATE (c.contract_expiration_date) "Expire Date",
    NULL "Header Status",
    NULL "Line Status",
    NULL "Line Type",
    NULL "Termination Reason",
    NULL "Location_id",
    NULL "Product_id"
    FROM edb_assets c,
    edb_accounts a
    WHERE controller_model_number_2 != 'NULL'
    AND serial_number_2 != 'NULL'
    AND C.Amid = A.Amid(+)
    union all
    SELECT 'Parature' "Source",
    NULL "Distibutor",
    reseller_name "Reseller",
    NULL "Reseller City",
    NULL "Reseller State",
    A.Country "Reseller Country",
    DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
    NULL "Customer Name",
    NULL "Customer City",
    NULL "Customer State",
    NULL "Customer Country",
    NULL "Customer Theater",
    NULL "Sales Book Date",
    NULL "Ship Date",
    c.sales_order_number "Sales Order Number",
    C.Po_Number "PO Number",
    controller_model_number_3 "Product Name",
    TRIM (UPPER (serial_number_3)) "Product Serial Number",
    c.contract_id "Contract ID",
    product_name "Support Name",
    TO_DATE (c.contract_purchase_date) "Start Date",
    TO_DATE (c.contract_expiration_date) "Expire Date",
    NULL "Header Status",
    NULL "Line Status",
    NULL "Line Type",
    NULL "Termination Reason",
    NULL "Location_id",
    NULL "Product_id"
    FROM edb_assets c,
    edb_accounts a
    WHERE controller_model_number_3 != 'NULL'
    AND serial_number_3 != 'NULL'
    AND C.Amid = A.Amid(+)
    union all
    SELECT 'Parature' "Source",
    NULL "Distibutor",
    reseller_name "Reseller",
    NULL "Reseller City",
    NULL "Reseller State",
    A.Country "Reseller Country",
    DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
    NULL "Customer Name",
    NULL "Customer City",
    NULL "Customer State",
    NULL "Customer Country",
    NULL "Customer Theater",
    NULL "Sales Book Date",
    NULL "Ship Date",
    c.sales_order_number "Sales Order Number",
    C.Po_Number "PO Number",
    controller_model_number_4 "Product Name",
    TRIM (UPPER (serial_number_4)) "Product Serial Number",
    c.contract_id "Contract ID",
    product_name "Support Name",
    TO_DATE (c.contract_purchase_date) "Start Date",
    TO_DATE (c.contract_expiration_date) "Expire Date",
    NULL "Header Status",
    NULL "Line Status",
    NULL "Line Type",
    NULL "Termination Reason",
    NULL "Location_id",
    NULL "Product_id"
    FROM edb_assets c,
    edb_accounts a
    WHERE controller_model_number_4 != 'NULL'
    AND serial_number_4 != 'NULL'
    AND C.Amid = A.Amid(+)
    union all
    SELECT 'Parature' "Source",
    NULL "Distibutor",
    reseller_name "Reseller",
    NULL "Reseller City",
    NULL "Reseller State",
    A.Country "Reseller Country",
    DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
    NULL "Customer Name",
    NULL "Customer City",
    NULL "Customer State",
    NULL "Customer Country",
    NULL "Customer Theater",
    NULL "Sales Book Date",
    NULL "Ship Date",
    c.sales_order_number "Sales Order Number",
    C.Po_Number "PO Number",
    controller_model_number_5 "Product Name",
    TRIM (UPPER (serial_number_5)) "Product Serial Number",
    c.contract_id "Contract ID",
    product_name "Support Name",
    TO_DATE (c.contract_purchase_date) "Start Date",
    TO_DATE (c.contract_expiration_date) "Expire Date",
    NULL "Header Status",
    NULL "Line Status",
    NULL "Line Type",
    NULL "Termination Reason",
    NULL "Location_id",
    NULL "Product_id"
    FROM edb_assets c,
    edb_accounts a
    WHERE controller_model_number_5 != 'NULL'
    AND serial_number_5 != 'NULL'
    AND C.Amid = A.Amid(+)
    union all
    SELECT 'ERP' "Source",
    Imv.Bill_To "Distibutor",
    Imv.Ship_To "Reseller",
    Ship_To_City "Reseller City",
    Ship_To_State "Reseller State",
    Edb2_Global.Country_Name_Theater(Imv.Ship_To_Country ,'COUNTRY') "Reseller Country",
    Edb2_Global.Country_Name_Theater(Imv.Ship_To_Country ,'THEATER') "Reseller Theater",
    Cl.Company_Name "Customer Name",
    Cl.City "Customer City",
    Cl.State "Customer State",
    Edb2_Global.Country_Name_Theater(Cl.Country,'COUNTRY') "Customer Country",
    Edb2_Global.Country_Name_Theater(Cl.Country,'THEATER') "Customer Theater",
    Imv.So_Booked_Date "Sales Book Date",
    Imv.Ship_Date "Ship Date",
    Imv.Order_Number "Sales Order Number",
    Imv.Cust_Po_Number "PO Number",
    Cp.Item_Name "Product Name",
    Cp.Product_Serial_Number "Product Serial Number",
    TO_CHAR(Imv.contract_number)"Contract ID",
    Imv.Service_Description "Support Name",
    Imv.Service_Start_Date "Start Date",
    Imv.Service_End_Date "Expire Date",
    Imv.Header_Status "Header Status",
    Imv.Line_Status "Line Status",
    Imv.Line_Type "Line Type",
    Imv.Termination_Reason "Termination Reason",
    Cl.Location_Id "Location_id",
    cp.id "Product_id"
    FROM ib_support_contracts_mv imv,
    customer_products cp,
    customer_locations cl
    WHERE Upper (Trim (Imv.Serial_Number)) = Upper (Trim (Cp.Product_Serial_Number(+)))
    AND Cp.Location_Id = Cl.Location_Id(+)) a
    Edited by: HuaMin on May 9, 2012 2:58 PM

  • Help needed in framing SQL query.

    Hi,
    I have table having following schema:
    PRODUCT_ID         INT
    DATE                   DATETIME
    ITEMS_SOLD         INT
    This table contains data for a week (sunday to saturday). I want to write an SQL query to get (filter out) PRODUCT_ID of products which has same no. of ITEMS_SOLD for all 7 days. Also for given PRODUCT_ID I need to find the longest period of successive days where the no. of ITEMS_SOLD is same for all days in this period. Eg.(PRODUCT_ID 23 was sold as following along the week in no. of units sold: 4,6,6,6,6,7,4 .So the longest period is *4 days* from Monday to Thursday.) The first condition is special case of second condition where no. of days is 7.
    Any help to get the SQL query will be appreciated.
    Thanks,
    Akshay.

    PRODUCT_ID      DATE           ITEMS_SOLD
    1          10/10/2011     3
    1          11/10/2011     3
    1          12/10/2011     3
    1          13/10/2011     3
    1           16/10/2011     5
    2          10/10/2011     4
    2           11/10/2011     4
    2          12/10/2011     4
    2          13/10/2011     4
    2           14/10/2011     4
    2          15/10/2011     4
    2          16/10/2011     4
    Output:
    PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
    1          3                4     
    2          4               7
    Explanation of results:
    The table to be queried contains data for 1 week: from 10/10/2011(Sunday) to 16/10/2011(Saturday). Now, product with PRODUCT_ID '1' was sold on dates 10,11,12,13,16. Out of these 5 days 3 units were sold on 4 successive days (from 10-13). So output should be like :
    PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
    1          3               4     
    as longest period of successive days is 4 where same no. of units were sold i.e 3 units (other period is of 1 day on 16th ).
    For PRODUCT_ID 2 we have only one period of 7 days where 4 units were sold each day. So we output :
    PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
    2           4               7
    Other case where same PRODUCT_ID have different units sold on each day should be ignored.
    I hope that clarifies the problem more. Let me know in case I have missed out anything which should have been mentioned.
    -Akshay.

  • Need help in rewriting a sql query

    Can any one please tell me if there is any utility that can help me correcting the sql I have I need to tune the query as its taking lot of time. I want to use some tool that will help me re-formating the query.
    Any help in this regard will be highly appreciated.

    If you think that Oracle SQL Tuning Tools like SQL Tuning Advisor and SQL Access Advisor are not helping.
    You might look into thrid party tools like Quest- SQL Navigator and TOAD.
    But I don't advise this based on the following:
    Re: Oracle Third Party Tools and Oracle Database
    Oracle have enough tools of its own to satisfy the various needs.
    Adith

  • How to view the sql query?

    hi,
      how to view the sql query formed from the xml structure in the receiver jdbc?

    You can view SAP Note at
    http://service.sap.com/notes
    But you require SMP login ID for this which you should get from your company. The content of the notes are as follows:
    Reason and Prerequisites
    You are looking for additional parameter settings. There are two possible reasons why a feature is available via the "additional parameters" table in the "advanced mode" section of the configuration, but not as documented parameter in the configuration UI itself:
    Category 1: The parameter has been introduced for a patch or a SP upgrade where no UI upgrade and/or documentation upgrade was possible. In this case, the parameter will be moved to the UI and the documentation as soon as possible. The parameter in the "additional parameters" table will be deprecated after this move, but still be working. The parameter belongs to the supported adapter functionality and can be used in all, also productive, scenarios.
    Category 2. The parameter has been introduced for testing purposes, proof-of-concept scenarios, as workaround or as pre-released functionality. In this case, the parameter may or may not be moved to the UI and documentation, and the functionality may be changed, replaced or removed. For this parameter category there is no guaranteed support and usage in productive scenarios is not supported.
    When you want to use a parameter documented here, please be aware to which category it belongs!
    Solution
    The following list shows all available parameters of category 1 or 2. Please note:
    Parameter names are always case-sensitive! Parameter values may be case-sensitive, this is documented for each parameter.
    Parameter names and values as documented below must be used always without quotaton marks ("), if not explicitly stated otherwise.
    The default value of a parameter is always chosen that it does not change the standard functionality
    JDBC Receiver Adapter Parameters
    1. Parameter name: "logSQLStatement"
                  Parameter type: boolean
                  Parameter value: true for any string value, false only for empty string
                  Parameter value default: false (empty String)
                  Available with: SP9
                  Category: 2
                  Description:
                  When implementing a scenario with the JDBC receiver adapter, it may be helpful to see which SQL statement is generated by the JDBC adapter from the XI message content for error analysis. Before SP9, this can only be found in the trace of the JDBC adapter if trace level DEBUG is activated. With SP9, the generated SQL statement will be shown in the details page (audit protocol) of the message monitor for each message directly.
                  This should be used only during the test phase and not in productive scenarios.
    Regards,
    Prateek

  • How to find out which Tables have been accessed without looking at the SQL query ?

    Hi,
    I would like to know is there a way to find out what queries have been executed and on which tables without looking at the SQL query.
    I have an old C++ code which calls some library functions to access the Oracle database. The source code for the library is not available to me yet. The functions selects/updates/deletes and inserts based on some input parameters I give. I do not know which tables it affects. How do I find out the actual SQL query and/or the tables it accesses ? I was told about V$SQL table that
    has the most recently executed queries, but
    I did'nt see any queries connected to my process.
    Could anybody help me on this ?
    Thanks
    Jagdeep
    [email protected]
    null

    PRECISE/SQL can help you if you have access to it
    2nd option can be that turn on SQL_TRACE
    Run executable of ur c++ program
    it will create a trace file in user_dump_dest
    and then using TKPROF u can see all quesries and their plan also.
    HTH
    Gagan Deep Singh
    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by (jagdeeps):
    Hi,
    I would like to know is there a way to find out what queries have been executed and on which tables without looking at the SQL query.
    I have an old C++ code which calls some library functions to access the Oracle database. The source code for the library is not available to me yet. The functions selects/updates/deletes and inserts based on some input parameters I give. I do not know which tables it affects. How do I find out the actual SQL query and/or the tables it accesses ? I was told about V$SQL table that
    has the most recently executed queries, but
    I did'nt see any queries connected to my process.
    Could anybody help me on this ?
    Thanks
    Jagdeep
    [email protected]<HR></BLOCKQUOTE>
    null

  • How to display the out put of the sql query in a text file using forms

    I want to display the out put of the sql query in a text file using forms 6.0.Same could be done using spool command in sqlplus but i want it using forms....Fiaz

    Have a look at the text_io package:
    http://www.oracle.com/webapps/online-help/forms/10g/state?navSetId=_&navId=3&vtTopicFile=f1_help/oraini/c_text_io.html&vtTopicId=
    cheers

  • The SQL query is not executing

    Hi
    I have the following situation: In a project we designed our reports calling a stored procedure the exits in a MS SQL Server 200 database. The Stored Procedures works fine and when they are used in the report everything works perfectly.
    The reports are being made with CR DEsigner 11, when the designer ends them, ha pass them to me and we put them in our java web application. I open them and even preview them since the Crystal Reprots Perspective of Eclipse and I can see the data, so everything to this point is OK.
    The problem comes when I change of connection, I'm trying to connect every report to the same host and database, and when the reprot is displayed in the browser there is no data. I profile the SQL commands that are executed when the report is requested and I found that the reprot is not executing the stored procedure.
    I guess because i'm connectring the report to the same database and host that was used when the report is created and i'm also passing exactly the same parameters of the stored procedure, then report thinks that it doesn't have executing again becuase it will be the same information.
    SO, i wonder if there is a way to request to the report to execute the sql query every time i have to display it.
    thanks for any help.

    What happens when you try to view the report using a simple viewer.jsp?without changing the connection?
    2009-05-25 14:06:09,250 ERROR com.businessobjects.reports.sdk.JRCCommunicationAdapter -  detected an exception: Error de conexión: [SQLServer 2000 Driver for JDBC]Error establishing socket.
    But the database server is ok, so i think the rpt needs more information to be connect to the database.
    Also what happens if you dont use the data bean and give everything there only?
    The same, the rpt is not executing the stored procedure.
    Did anything change on the RDBMS side? Additional packages, changes to the schema, ownership, etc?
    No, the server is ok and the database is ok.
    If you configure Log4J logging to DEBUG, you should see the database invokes from the Crystal Java engine, specifically the queries sent and the number of rowsets returned. Do you notice any errors?
    I have a problem here with log4j. In my project i'm using spring and with the help of spring i configure log4j, basically with spring is easier to configure log4j.
    I'm telling you this because i have log4j working but when my application reaches the code to change the connection to the rerport, log4j dies and stop sending any message to the stdout or to a log file. I haven't since this behavior in any other app o library. So i want to guess i have something wrong with my log4j or maybe with log4j+spring.
    So, i remove all the code of spring referring to log4j, but the problem with log4j wasn't solved.
    What i will try now is to remove spring from the project.
    This is my log4j.properties:
    log4j.rootLogger=DEBUG, stdout
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n

  • I want to use the SQL query IF EXIST to update or insert data in a ms access table, but it doesn´t work

    Hi,
    I want to use the SQL query IF EXIST to update or insert data in a ms access table, but it doesn´t work
    (fault number -2147217900)
    I want to search for a value in a ms access table , if it exist i want to update it, if not i want to insert a new row.
    Working with LabView 7.1, database con. toolset.
    Who can HELP?
    Thanks a lot
    Marco

    Hello,
    I think that If exist is not a standar SQL command (I know it exists I think in Oracle and SQL server), MS access doesn't support it, so I think the best way to do it is first make a Select and then either an Update or an insert, sorry...
    Paulo

  • Can anybody provide the SQL query to find the files uploaded in a particular folder?

    Hi All,
    Can anybody provide the SQL query to find the documents (document name) uploaded in a particular folder? While clicking on folder in
    GUI I'm hitting the Timeout error. I would like to find the files uploaded into this folder from SQLPLUS.
    Any help is greatly appreciated.
    With best regards,
    Nevin

    Nevin,
    Be great if we could know the version of Portal. For Rel. 1, here's the query
    select id,masterthingid from wwv_things
    where siteid = &site
    and cornerid = &corner
    &site - Content Area id
    &corner - Folder id
    if you don't know the folder id, use
    select id from wwv_corners where siteid = &site
    and name = &folder
    Hope this helps. I have run into this situation before. Usually, the culprits were
    one of the following:
    1. Junk Characters in description of item (caused due to Copy-Paste)
    2. Special Characters in the File name
    Hi All,
    Can anybody provide the SQL query to find the documents (document name) uploaded in a particular folder? While clicking on folder in
    GUI I'm hitting the Timeout error. I would like to find the files uploaded into this folder from SQLPLUS.
    Any help is greatly appreciated.
    With best regards,
    Nevin

  • How does Index fragmentation and statistics affect the sql query performance

    Hi,
    How does Index fragmentation and statistics affect the sql query performance
    Thanks
    Shashikala
    Shashikala

    How does Index fragmentation and statistics affect the sql query performance
    Very simple answer, outdated statistics will lead optimizer to create bad plans which in turn will require more resources and this will impact performance. If index is fragmented ( mainly clustered index,holds true for Non clustred as well) time spent in finding
    the value will be more as query would have to search fragmented index to look for data, additional spaces will increase search time.
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers
    My TechNet Wiki Articles

  • Report data  does not reflect the SQL Query?

    Hi,
    I have a report which does not seem to be processing all records returned from the database. When I run the SQL Query produced by crystal manually against the SQL Server all data is returned correctly in crystal not. Does this mean my links are not set up correctly in the Database Expert? or is there another issue, I use a Crystal Syntax selection formulae which is based on a couple of paramters to filter the database records.
    Help is appreciated
    K

    <p>I agree with Rahul on checking the record count on the report vs. the record count from the query.  Conditional suppression and Group selection formula will hide records that are actually being returned.</p><p>It sounds like (from your question) that you are using the database linking expert in CR.  You can also check the SQL that CR is sending by going to Database -> Show SQL Query... compare this with the query you are using for validation, this will give you some clues as to whether your linking structure has an issue. </p>

Maybe you are looking for