How to tune this query for the improve performance ?

Hi All,
How to tune this query for the improve performance ?
select a.claim_number,a.pay_cd,a.claim_occurrence_number,
case
when sum(case
when a.payment_status_cd ='0'
then a.payment_est_amt
else 0
end
)=0
then 0
else (sum(case
when a.payment_status_cd='0'and a.payment_est_amt > 0
then a.payment_est_amt
else 0
end)
- sum(case
when a.payment_status_cd<>'0'
then a.payment_amt
else 0
end))
end as estimate
from ins_claim_payment a
where a.as_of_date between '31-jan-03' and '30-aug-06'
and ( a.data_source = '25' or (a.data_source between '27' and '29'))
and substr(a.pay_cd,1,1) IN ('2','3','4','8','9')
group by a.claim_number, a.pay_cd, a.claim_occurrence_number
Thank you,
Mcka

Mcka
As well as EXPLAIN PLAN, let us know what proportion of rows are visited by this query. It may be that it is not using a full table scan when it should (or vice versa).
And of course we'd need to know what indexes are available, and how selective they are for the predicated you have in this query ...
Regards Nigel

Similar Messages

  • How to select this field  for the extractor?

    Hi Gurus, I hope you are fine!
    I need to extract the field     PRED_OPPT_GUID   form the Data source  0CRM_SRV_CONTRACT_H inside CRM system.
    If I go inside CRM to:   
    Transaction SBIW -> Settings for BW Adapter -> Maintain DataSource and Enhance BW Adapter Metadata ->
    tipe "0CRM_SRV_CONTRACT_H" and press change buttom -> Mapping TAB
    there I can see the field I need "PRED_OPPT_GUID"  but this is not selected at the "BW Selection" Column , I guess this is the cause why I am not receiving this field from the extractor, Am I right?
    If yes, How can I select this field  for the "BW Selection" Column? (the system does not allow me to click it directly)
    if not, what is the proper procedure if I need to extract this field ? because this is the key field  for  the DSO 
    " Service Orders: Header Data "
    Thanks

    This is what i can see inside the  ROOSFIELD table:
    Filtered by data source = 0CRM_SRV_PROCESS_H
    Comparison with another field:
    BILL_TO_PARTY  (working properly)    columns:        SELECTION = X              NOTEXREL= Y
    PRED_OPPT_GUID (Not working)           columns:        SELECTION = (Empty)    NOTEXREL= Y
    I think that if I try to change the Selection field to X it will cause inconsistencies with the SMOXRELP table am I right ?
    I tried to change using the system and not directly into the tables, but thaere was an inconsitecie between these 2 tables.
    Why is no able this field taking into account that this is the KEY FIELD inside the standard DSO? it has no sense to me.
    What do you think?
    regards.

  • How to write selection Query for the following requirment.

    Hi All,
    I am new to ABAP, I need a help ,
    I need to select all plants(WERKS) from MARC at Plant/Material level,
    then I need to take all sales organozation(VKORG) from T001w,
    then I need the company code(BUKRS) from TVKO based on VKORG,
    then I need the currency key(WAERS) from T001 based on BUKRS,
    Can any one help me in writing selection Query for the same?
    Thanks All,
    Debrup.

    Hi,
    Its easy for you if you learn SELECT with JOIN to complete your task. So SEARCH the forum with SELECT statement and you will get a lot of examples using which you can write your own.
    If you struck up anywhere revert back.
    Regards
    Karthik D

  • How to tune this query

    Hi,
    Im trying to select the latest set of data from a table using a simple query for inserting into a new table.
    Details are given below.
    There are no indices for the table. Its taking around 18 sec.
    Pls advice on how to proceed so that I can bring down this time.
    Query:
    SELECT
    FROM
    M_UNDR M
    WHERE
    M.M_DATE = (SELECT MAX(M_DATE) FROM M_UNDR M1)
    AND
    M.M_TIME =
    SELECT MAX(M_TIME) FROM M_UNDR M2 WHERE M2.M_DATE = M.M_DATE
    AND
    M.U_TYPE NOT IN ('USD', 'GBP', 'EUR');
    SQL> select count(1) from m_undr;
      COUNT(1)
       2695446
    SQL>
    Version:
    SQL> select banner from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for Solaris: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    Explain plan
    PLAN_TABLE_OUTPUT
    | Id  | Operation            | Name           | Rows  | Bytes | Cost  |
    |   0 | SELECT STATEMENT     |                |     1 |    95 | 19060 |
    |   1 |  HASH JOIN           |                |     1 |    95 | 12882 |
    |   2 |   VIEW               | VW_SQ_1        |   508 | 11176 |  6608 |
    |   3 |    HASH GROUP BY     |                |   508 | 10668 |  6608 |
    |   4 |     TABLE ACCESS FULL| M_UNDR |  2392K|    47M|  6186 |
    |   5 |   TABLE ACCESS FULL  | M_UNDR |  5594 |   398K|  6274 |
    |   6 |    SORT AGGREGATE    |                |     1 |     8 |       |
    |   7 |     TABLE ACCESS FULL| M_UNDR |  2392K|    18M|  6178 |
    SQL> sho parameter optimizer
    NAME                                 TYPE        VALUE
    optimizer_dynamic_sampling           integer     2
    optimizer_features_enable            string      10.2.0.3
    optimizer_index_caching              integer     0
    optimizer_index_cost_adj             integer     200
    optimizer_mode                       string      ALL_ROWS
    optimizer_secure_view_merging        boolean     TRUE
    SQL> sho parameter DB_FILE_MULTI
    NAME                                 TYPE        VALUE
    db_file_multiblock_read_count        integer     16
    SQL> show parameter db_block_size
    NAME                                 TYPE        VALUE
    db_block_size                        integer     8192
    SQL> show parameter cursor_sharing
    NAME                                 TYPE        VALUE
    cursor_sharing                       string      EXACT
    Trace:
    SQL> set autotrace traceonly arraysize 100
    SQL> SELECT
      2  *
      3  FROM
      4  M_UNDR M
      5  WHERE
      6  M.M_DATE = (SELECT MAX(M_DATE) FROM M_UNDR M1)
      7  AND
      8  M.M_TIME =
      9  (
    10  SELECT MAX(M_TIME) FROM M_UNDR M2 WHERE M2.M_DATE = M.M_DATE
    11  )
    12  AND
    13  M.U_TYPE NOT IN ('USD', 'GBP', 'EUR');
    239 rows selected.
    Execution Plan
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=19060 Card=1 Bytes
              =95)
       1    0   HASH JOIN (Cost=12882 Card=1 Bytes=95)
       2    1     VIEW OF 'VW_SQ_1' (VIEW) (Cost=6608 Card=508 Bytes=11176
       3    2       HASH (GROUP BY) (Cost=6608 Card=508 Bytes=10668)
       4    3         TABLE ACCESS (FULL) OF 'M_UNDR' (TABLE) (Cos
              t=6186 Card=2392724 Bytes=50247204)
       5    1     TABLE ACCESS (FULL) OF 'M_UNDR' (TABLE) (Cost=62
              74 Card=5594 Bytes=408362)
       6    5       SORT (AGGREGATE)
       7    6         TABLE ACCESS (FULL) OF 'M_UNDR' (TABLE) (Cos
              t=6178 Card=2392724 Bytes=19141792)
    Statistics
              1  recursive calls
              0  db block gets
          91479  consistent gets
           4830  physical reads
              0  redo size
          15457  bytes sent via SQL*Net to client
            359  bytes received via SQL*Net from client
              4  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
            239  rows processed
    SQL> disconnect
    SQL> select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
    PLAN_TABLE_OUTPUT
    SQL_ID  0br4mzjgj63dw, child number 0
    SELECT /*+ gather_plan_statistics */ * FROM M_UNDR M WHERE M.M_DATE = (SELECT MAX(M_DATE) FROM
    M_UNDR M1) AND M.M_TIME = ( SELECT MAX(M_TIME) FROM M_UNDR M2 WHERE M2.M_DATE = M.M_DATE )
    AND M.U_TYPE NOT IN ('USD', 'GBP', 'EUR')
    Plan hash value: 1220141218
    | Id  | Operation            | Name           | Starts | E-Rows | A-Rows |   A-Time   | Buffers |  OMem |  1Mem | Used-Mem |
    |*  1 |  HASH JOIN           |                |      1 |      1 |    239 |00:00:06.94 |   91479 |  1114K|  1114K| 1209K (0)|
    |   2 |   VIEW               | VW_SQ_1        |      1 |    508 |    607 |00:00:04.06 |   30492 |    |  |          |
    |   3 |    HASH GROUP BY     |                |      1 |    508 |    607 |00:00:04.06 |   30492 |    |  |          |
    |   4 |     TABLE ACCESS FULL| M_UNDR |      1 |   2392K|   2695K|00:00:00.01 |   30492 |    |  |          |
    |*  5 |   TABLE ACCESS FULL  | M_UNDR |      1 |   5594 |   5497 |00:00:02.81 |   60987 |    |  |          |
    |   6 |    SORT AGGREGATE    |                |      1 |      1 |      1 |00:00:01.20 |   30492 |    |  |          |
    |   7 |     TABLE ACCESS FULL| M_UNDR |      1 |   2392K|   2695K|00:00:00.01 |   30492 |    |  |          |
    Predicate Information (identified by operation id):
       1 - access("M"."M_TIME"="VW_COL_1" AND "M_DATE"="M"."M_DATE")
       5 - filter(("M"."U_TYPE"<>'USD' AND "M"."U_TYPE"<>'GBP' AND "M"."U_TYPE"<>'EUR' AND "M"."M_DATE"=))
    26 rows selected.I have tried using rank as below. Didnt find any improvement.
    select * from
    SELECT
    m.*,
    rank() over (order by m_date desc, m_time desc) rnk
    FROM
    M_UNDR M
    WHERE
    M.U_TYPE NOT IN ('USD', 'GBP', 'EUR')
    where rnk  = 1Thanks in advance

    Hi,
    creating index on m_date and m_time did have gr8 impact on the plan.
    Query is completing in 2 sec now.
    Id  | Operation                      | Name               | Rows  | Bytes | Cost  |
       0 | SELECT STATEMENT               |                    |     1 |    73 |  6234 |
       1 |  TABLE ACCESS BY INDEX ROWID   | M_UNDR     |     2 |   146 |    51 |
       2 |   INDEX RANGE SCAN             | IND_M_UNDR |     2 |       |    49 |
       3 |    SORT AGGREGATE              |                    |     1 |    13 |       |
       4 |     FIRST ROW                  |                    |  5683 | 73879 |     6 |
       5 |      INDEX RANGE SCAN (MIN/MAX)| IND_M_UNDR |  5683 | 73879 |     6 |
       6 |    SORT AGGREGATE              |                    |     1 |     8 |       |
       7 |     INDEX FULL SCAN (MIN/MAX)  | IND_M_UNDR |  2392K|    18M|       |
    ------------------------------------------------------------------------------------Thanks for the help. Will check if there is any serious impact on insert.

  • How to write a query for the given scenario ?

    Hi All ,
    I am having two tables EMP, DEPT with the below data.
    EMP TABLE :--
    EID     ENAME     JOB     SAL     DEPID
    111     RAM     MANAGER     1500     10
    222     SAM     ASST MANAGER     2000     20
    333     KALA     CLERK     2500     10
    444     BIMA     MANAGER     3000     20
    555     CHALA     MANAGER     3500     30
    666     RANI     ASST MANAGER     4000     10
    777     KAMAL     MANAGER     2400     10
    DEPT TABLE :--
    DEPID     DNAME
    10     XX
    20     YY
    30     ZZ
    Q1 : I want the sum of salary of each department and for the particular job . Here in each departmant manager, asst. manager, clerk posts are there .
    I want to display the result like below ....
    JOB     10     20     30
    MANAGER     3900     3000     3500
    ASST MANAGER 4000     2000     NULL
    CLERK     2500     NULL     NULL
    please tell me how to write a sql query ?
    Thanks
    Sai

    In general case, you cannot write this query.
    This is one of the limits of relational database concepts. The number of columns must be known up-front. In the SELECT clause, you have to list and name all columns returned by the query. So you have to know number of departments. (There are some workarounds - you can return one column with concatenated values for all departments, separated by space character).
    If you know that you have 3 departments then you qurey will return 4 columns:
    SELECT
       e.job,
       SUM ( CASE WHEN d.deptid = 10 THEN e.sal ELSE NULL END) d10,
       SUM ( CASE WHEN d.deptid = 20 THEN e.sal ELSE NULL END) d20,
       SUM ( CASE WHEN d.deptid = 30 THEN e.sal ELSE NULL END) d30
    FROM dept d, emp e
    WHERE d.deptno = e.deptno
    GROUP BY e.job

  • How to write a query for the following issue

    Hello,
    I would like to write a query to display the result in the following format 
    Item
    Categort1
    Categort2
    Categort3
    Categort4
    Categort5
    Categort6
    Min
    Max
    Avg
    Min
    Max
    Avg
    Min
    Max
    Avg
    Min
    Max
    Avg
    Min
    Max
    Avg
    Min
    Max
    Avg
    01
    02
    03
    04
    For every item for the category i need to find Min,Max and Avg from the Value column
    Table structure is as follows
    ID
    Item Id
    Item
    Category
    value
    1
    01
    A
    Categort1
    1
    2
    01
    A
    Categort1
    2
    3
    01
    A
    Categort1
    3
    4
    02
    B
    Categort2
    7
    5
    02
    B
    Categort2
    8
    6
    03
    C
    Categort3
    6
    7
    04
    D
    Categort4
    12
    8
    04
    D
    Categort4
    14

    SELECT ItemID,
    MIN(CASE WHEN Category = 'Categort1' THEN value END) AS Min_category1,
    MAX(CASE WHEN Category = 'Categort1' THEN value END) AS Max_category1,
    AVG(CASE WHEN Category = 'Categort1' THEN value END) AS Avg_category1,
    MIN(CASE WHEN Category = 'Categort2' THEN value END) AS Min_category2,
    MAX(CASE WHEN Category = 'Categort2' THEN value END) AS Max_category2,
    AVG(CASE WHEN Category = 'Categort2' THEN value END) AS Avg_category2,
    MIN(CASE WHEN Category = 'Categort6' THEN value END) AS Min_category6,
    MAX(CASE WHEN Category = 'Categort6' THEN value END) AS Max_category6,
    AVG(CASE WHEN Category = 'Categort6' THEN value END) AS Avg_category6
    FROM Table
    GROUP BY ItemID
    The format can be achieved using tools like SSRS
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to find out query for the deleted record.

    Hi Guys,
    We are using Oracle9i release 1. We are about 5 employees who are working on the same application. All Employee are connected to the same Schema (User)
    User: Employee/web
    Now one of the user have deleted like 200,000 records from a table. We just want to trace out the query by which these records were deleted.
    From which file i can get the log of executed queries so that i can recover the data.
    Just want to know the query executed for this deletion of records?
    we are using windows server.
    Regards,
    Imran Baig

    If you do not need an exact query, but only the way you can reconstruct the data, LogMiner can be solution for you. Below I have put a simple example – you can review it if you want.
    [email protected]> create table t201 as select object_id , object_name from all_objects where rownum < 10;
    Table created.
    [email protected]> select * from t201;
    OBJECT_ID OBJECT_NAME
    17918 /1005bd30_LnkdConstant
    7540 /10076b23_OraCustomDatumClosur
    23355 /10297c91_SAXAttrList
    14204 /103a2e73_DefaultEditorKitEndP
    22920 /1048734f_DefaultFolder
    10154 /10501902_BasicFileChooserUINe
    23566 /105072e7_HttpSessionBindingEv
    23621 /106ba0a5_ArrayEnumeration
    9830 /106faabc_BasicTreeUIKeyHandle
    9 rows selected.
    [email protected]> delete t201 where object_id < 10000;
    2 rows deleted.
    [email protected]> commit;
    Commit complete.
    [email protected]> alter system switch logfile;
    System altered.
    [email protected]> select * from v$log;
    GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM
    1 1 41 10485760 2 YES ACTIVE 58320830 25-MAR-06
    2 1 42 10485760 1 NO CURRENT 58348006 25-MAR-06
    3 1 40 10485760 1 YES INACTIVE 58293190 25-MAR-06
    [email protected]> select * from v$archived_log where sequence# = 41;
    RECID STAMP
    NAME
    DEST_ID THREAD# SEQUENCE# RESETLOGS_CHANGE# RESETLOGS FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME BLOCKS
    ARC APP
    DEL S COMPLETIO DIC DIC END BACKUP_COUNT ARCHIVAL_THREAD# ACTIVATION#
    86 585998848
    C:\ORACLE\ORADATA\MOB92\ARCH\ARC00041.001
    1 1 41 57407039 20-MAR-06 58320830 25-MAR-06 58348006 25-MAR-06 20282
    YES NO
    NO A 25-MAR-06 NO NO NO 0 1 2555135919
    [email protected]> exec dbms_logmnr.add_logfile('C:\ORACLE\ORADATA\MOB92\ARCH\ARC00041.001',dbms_logmnr.new)
    PL/SQL procedure successfully completed.
    [email protected]> exec dbms_logmnr.start_logmnr(options => dbms_logmnr.dict_from_online_catalog)
    PL/SQL procedure successfully completed.
    [email protected]> l
    1 select sql_undo, sql_redo
    2 from v$logmnr_contents
    3 where username = 'MOB' and timestamp > sysdate - 1
    4* order by timestamp
    insert into "MOB"."T201"("OBJECT_ID","OBJECT_NAME") values ('7540','/10076b23_OraCustomDatumClosur');
    delete from "MOB"."T201" where "OBJECT_ID" = '7540' and "OBJECT_NAME" = '/10076b23_OraCustomDatumClosur' and ROWID = 'AAAIE2AAXAAAFVaAAB';
    insert into "MOB"."T201"("OBJECT_ID","OBJECT_NAME") values ('9830','/106faabc_BasicTreeUIKeyHandle');
    delete from "MOB"."T201" where "OBJECT_ID" = '9830' and "OBJECT_NAME" = '/106faabc_BasicTreeUIKeyHandle' and ROWID = 'AAAIE2AAXAAAFVaAAI';
    Best Regards
    Krystian Zieja / mob

  • How to build this query with the minumum number of sub-selects?

    The question I am trying to answer is analogous to this:
    Give me all projects that: (have no employees assigned and are small) or (have only employees with the the last name = "Smith")
    Thanks,
    Roman

    Thank you :
    1- I am in 9.0.4.8 version and can not use allOf expression (availible in beta version)
    2- I not find .notIn(subQuery) operator in 9.0.4.8 version and i replace it by .in(subQuery).not() !
    My new query retrieve Customer who have 0 (zéro) Orders !
    How to retrieve only customer (with orders + with orders without "television") ?
    My new query is :
    <div align="left" class="java">
    <font color="#7f0055"><b>static </b></font><font color="#7f0055"><b>void </b></font><font color="#000000">findCustNoComputer </font><font color="#000000">(){</font>
    <font color="#ffffff">   </font><font color="#000000">ClientSession cs = TopLinkSession.acquireClientSession</font><font color="#000000">()</font><font color="#000000">;</font>
    <font color="#ffffff"></font>
    <font color="#ffffff"></font>
    <font color="#ffffff">  </font><font color="#000000">ReadAllQuery query = </font><font color="#7f0055"><b>new </b></font><font color="#000000">ReadAllQuery</font><font color="#000000">(</font><font color="#000000">Customer.</font><font color="#7f0055"><b>class</b></font><font color="#000000">)</font><font color="#000000">;</font>
    <font color="#ffffff">  </font><font color="#000000">ExpressionBuilder queryBuilder = query.getExpressionBuilder</font><font color="#000000">()</font><font color="#000000">;</font>
    <font color="#ffffff"></font>
    <font color="#ffffff">  </font><font color="#000000">ExpressionBuilder subqueryBuilder = </font><font color="#7f0055"><b>new </b></font><font color="#000000">ExpressionBuilder</font><font color="#000000">(</font><font color="#000000">Customer.</font><font color="#7f0055"><b>class</b></font><font color="#000000">)</font><font color="#000000">;</font>
    <font color="#ffffff">  </font><font color="#000000">ReportQuery subQuery = </font><font color="#7f0055"><b>new </b></font><font color="#000000">ReportQuery</font><font color="#000000">(</font><font color="#000000">Customer.class, subqueryBuilder</font><font color="#000000">)</font><font color="#000000">;</font>
    <font color="#ffffff">  </font><font color="#000000">subQuery.addAttribute</font><font color="#000000">(</font><font color="#2a00ff">&#34;id&#34;</font><font color="#000000">)</font><font color="#000000">;</font>
    <font color="#ffffff">  </font><font color="#000000">subQuery.setSelectionCriteria</font><font color="#000000">(</font><font color="#000000">subqueryBuilder.anyOf</font><font color="#000000">(</font><font color="#2a00ff">&#34;Orders&#34;</font><font color="#000000">)</font><font color="#000000">.anyOf</font><font color="#000000">(</font><font color="#2a00ff">&#34;OrderItems&#34;</font><font color="#000000">)</font><font color="#000000">.get</font><font color="#000000">(</font><font color="#2a00ff">&#34;product&#34;</font><font color="#000000">)</font><font color="#000000">.get</font><font color="#000000">(</font><font color="#2a00ff">&#34;productName&#34;</font><font color="#000000">)</font><font color="#000000">.equal</font><font color="#000000">(</font><font color="#2a00ff">&#34;Computer&#34;</font><font color="#000000">))</font><font color="#000000">;</font>
    <font color="#ffffff">  </font><font color="#000000">query.setSelectionCriteria</font><font color="#000000">(</font><font color="#000000">queryBuilder.get</font><font color="#000000">(</font><font color="#2a00ff">&#34;id&#34;</font><font color="#000000">)</font><font color="#000000">.in</font><font color="#000000">(</font><font color="#000000">subQuery</font><font color="#000000">)</font><font color="#000000">.not</font><font color="#000000">())</font><font color="#000000">;</font>
    <font color="#ffffff"></font>
    <font color="#ffffff">   </font><font color="#000000">Vector allCustomers = </font><font color="#000000">(</font><font color="#000000">Vector</font><font color="#000000">)</font><font color="#000000">cs.executeQuery</font><font color="#000000">(</font><font color="#000000">query</font><font color="#000000">)</font><font color="#000000">;</font>
    <font color="#ffffff">   </font><font color="#000000">Iterator allCustomersIterator = allCustomers.iterator</font><font color="#000000">()</font><font color="#000000">;</font>
    <font color="#ffffff">   </font><font color="#7f0055"><b>while </b></font><font color="#000000">(</font><font color="#000000">allCustomersIterator.hasNext</font><font color="#000000">()) </font>
    <font color="#ffffff">   </font><font color="#000000">{</font>
    <font color="#ffffff">     </font><font color="#000000">Customer tempCustomer = </font><font color="#000000">(</font><font color="#000000">Customer</font><font color="#000000">)</font><font color="#000000">allCustomersIterator.next</font><font color="#000000">()</font><font color="#000000">;</font>
    <font color="#ffffff">        </font><font color="#000000">System.out.println</font><font color="#000000">(</font><font color="#000000">tempCustomer</font><font color="#000000">)</font><font color="#000000">;</font>
    <font color="#ffffff">   </font><font color="#000000">}</font>
    <font color="#ffffff">   </font><font color="#000000">cs.release</font><font color="#000000">()</font><font color="#000000">;</font>
    <font color="#000000">}</font>
    <font color="#ffffff"></font>
    <font color="#ffffff"></font>
    Sql of query :
    SELECT
         t0.CUST_LAST_NAME, t0.CUST_FIRST_NAME, t0.CREDIT_LIMIT, t0.CUST_EMAIL, t0.CUSTOMER_ID, t0.PHONE_NUMBER2, t0.PHONE_NUMBER1, t0.CUST_STREET_ADDRESS1, t0.CUST_CITY, t0.CUST_STREET_ADDRESS2, t0.CUST_STATE, t0.CUST_POSTAL_CODE
    FROM TL_CUSTOMER t0
    WHERE NOT (
         (t0.CUSTOMER_ID IN
              (SELECT DISTINCT t1.CUSTOMER_ID
              FROM TL_CUSTOMER_ORDER t4, TL_ORDER_ITEM t3, TL_PRODUCT t2, TL_CUSTOMER t1
              WHERE (
                   (t2.PRODUCT_NAME = ?) AND
                   ((t2.PRODUCT_ID = t3.PRODUCT_ID) AND
                        ((t3.ORDER_ID = t4.ORDER_ID) AND (t4.CUSTOMER_ID = t1.CUSTOMER_ID)))))))
    Regards

  • Some Basic steps How to tune this Query

    Hi All
    This is my cursor Query to fetch the Eligible orders its taking too much of time to execute, This is my query
    SELECT oeol.header_id,oeol.attribute1,oeoh.order_number,COUNT(1) consignment_count
    FROM oe_order_lines_all oeol,oe_order_headers_all oeoh,oe_transaction_types_all oett
    WHERE oeol.header_id = oeoh.header_id
    AND oeol.flow_status_code IN(DECODE(oett.name,xxhdnl_om_common_util_pkg.g_push_line_type,
    DECODE(oeol.shipment_priority_code,'EXPRESS',DECODE(oeol.flow_status_code,'AWAITING_STOCK'
    ,'AWAITING_STOCK','STOCK_RECEIVED','STOCK_RECEIVED'),'STOCK_RECEIVED')
    ,DECODE(XXHDNL_OM_QUI_BAT_PLAN_EXT_PKG.check_push_or_pull(oeol.line_id),'PUSH','BOOKED')))
    AND(oeol.shipment_priority_code=p_shipment_priority OR p_shipment_priority IS NULL)
    AND oeol.line_type_id =oett.transaction_type_id AND oett.name IN
    (xxhdnl_om_common_util_pkg.g_return_line_type
    ,xxhdnl_om_common_util_pkg.g_push_line_type )
    AND oeoh.attribute3 IS NULL
    GROUP BY
    oeol.header_id
    ,oeol.attribute1
    ,oeoh.order_number;
    Pls provide some basic steps for tuning regarding some performance.
    thanks & regards
    Srikkanth.M

    Hi
    as I tried to say is that DECODE is just hard to read, but not a performance issue.
    What do you do in the XXHDNL_OM_QUI_BAT_PLAN_EXT_PKG.check_push_or_pull(oeol.line_id) procedure?
    But let me try the DECODE... not 100% correct as I can't test but you'll get the picture:
    SELECT
    FROM
    WHERE oeol.flow_status_code IN
    CASE WHEN oett.name = xxhdnl_om_common_util_pkg.g_push_line_type THEN
       CASE WHEN oeol.shipment_priority_code = 'EXPRESS' THEN
          CASE WHEN oeol.flow_status_code ='AWAITING_STOCK' THEN 'AWAITING_STOCK'
               WHEN oeol.flow_status_code ='STOCK_RECEIVED' THEN 'STOCK_RECEIVED'
               ELSE null END
          ELSE
          CASE WHEN XXHDNL_OM_QUI_BAT_PLAN_EXT_PKG.check_push_or_pull(oeol.line_id) = 'PUSH' THEN 'BOOKED'
             ELSE NULL END
    ELSE
    NULL
    ENDThat is a 1:1 "translation" PLEASE add comments in nested statements.
    And this is easier to read, as in CASE you can use AND / OR / IN ....
    SELECT
    FROM
    WHERE oeol.flow_status_code IN
    CASE WHEN oett.name = xxhdnl_om_common_util_pkg.g_push_line_type THEN
       CASE WHEN oeol.shipment_priority_code = 'EXPRESS' AND oeol.flow_status_code IN ('AWAITING_STOCK','STOCK_RECEIVED')
         THEN oeol.flow_status_code ELSE NULL END
       ELSE
        CASE WHEN XXHDNL_OM_QUI_BAT_PLAN_EXT_PKG.check_push_or_pull(oeol.line_id) = 'PUSH' THEN 'BOOKED'
             ELSE NULL END
    ENDThe "oeol.flow_status_code IN" makes no sense as the output of/DECODE/CASE is always 1 value right? And I would use the logic on a select on table "oe_order_lines_all" and then use the calculated field as a JOIN criteria. Much easier to test and read.
    But, please check the procedure which you call that can be deadly! The "case" is just "nice to have"
    -- andy

  • Hi.how to tune this query?

    select *
    from exp_final
    where
    to_number(to_char(process_date,'mm'))=to_number(to_char(sysdate,'mm'))-1

    Both Sven's and theoa's suggestions are fundamentally different from the query OP referred to originally.
    It maybe that the original query is completely wrong (that would be my instinct too).
    Original query:
    select *
    from exp_final
    where
    to_number(to_char(process_date,'mm'))=to_number(to_char(sysdate,'mm'))-1 implies that you want everything from exp_final where the process_date was in the same month as the current month -1, regardless of year. For example, run today this will bring back everything done in a December, whether it was December 1972, December 1815 or December 2010.
    Whereas their suggestions rely on your query being wrong and what you really want to get is everything from last month - i.e. run today, fetch everything from December 2010.
    Which is the correct requirement?

  • Plz help me in this query for the tree

    hi All
    I want to bulid tree that start with for example
    schema name "scott"
    then table "dept,emp
    then ename in table emp
    root scott
    parent dept
    child emp_name
    please help me in the query ?

    user222 wrote:
    any help my dearsIf you can draw one simple tree example. Then it will be easy to create query. Because i am confuse about the output. Just draw one example of your desired output tree. Then it will help to find solution.
    And while writing query or any example so use the 6 digit before and after your query or example to keep the formatting in orignal format. Otherwise it becomes hard to read.
    For more information see FAQ on right corner for page.
    -Ammad                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to write a Query for the mentioned scenario.

    Hi All,
    Table A
    ID|| Start_Date||End_date||Rate
    1||01-Jan-2011||31-Mar-2011||0.8
    1||01-Apr-2011||31-Jun-2011||0.9
    I have a table like above. I want to write a query to display the result as below.
    ID|| Start_Date||Rate
    1||01-Jan-2011||0.8
    1||01-Feb-2011||0.8
    1||01-Mar-2011||0.8
    1||01-Apr-2011||0.9
    1||01-May-2011||0.9
    1||01-Jun-2011||0.9
    Kindly help.
    Thanks!
    GJ

    Try to read link mentioned by SB. It will make you more interactive to share your problems. And immediate reply too from experts.
    Check your solution below.
    SQL> ed
    Wrote file afiedt.buf
      1  WITH data1 AS
      2  (
      3  SELECT 1 id, TO_DATE('01-Jan-2011' , 'DD-Mon-YYYY') stdt,TO_DATE('31-Mar-2011' , 'DD-Mon-YYYY') endt, 0.8 rate FROM dual
      4  UNION ALL
      5  SELECT 1 id, TO_DATE('01-Apr-2011' , 'DD-Mon-YYYY') stdt,TO_DATE('30-Jun-2011' , 'DD-Mon-YYYY') endt, 0.9 rate FROM dual
      6  )
      7  SELECT id, ADD_MONTHS(stdt, level -1) st_dt, rate FROM data1
      8  CONNECT BY  level <= ROUND(MONTHS_BETWEEN(endt,stdt))
      9  AND rate= prior rate  /* stick to current line */
    10* AND prior sys_guid() IS NOT NULL  /* used to terminate the connect by loop */
    SQL> /
            ID ST_DT           RATE
             1 01-JAN-11         .8
             1 01-FEB-11         .8
             1 01-MAR-11         .8
             1 01-APR-11         .9
             1 01-MAY-11         .9
             1 01-JUN-11         .9
    6 rows selected.Thanks!
    Ashutosh
    Edited by: Ashu_Neo on Oct 8, 2012 11:57 AM

  • How to modify this query to get the desired output format

    I hv written a Query to display all the parent table names and their primary key columns(relevant to this foreign key of the child table).The query is given below...
    SELECT DISTINCT(TABLE_NAME) AS PARENT_TABLE,COLUMN_NAME AS PARENT_COLUMN
    FROM ALL_CONS_COLUMNS
    WHERE CONSTRAINT_NAME IN (SELECT AC.R_CONSTRAINT_NAME
    FROM ALL_CONSTRAINTS AC
    WHERE AC.TABLE_NAME=TABLE_NAME
    AND AC.TABLE_NAME='&TABLE'
    AND AC.R_CONSTRAINT_NAME IS NOT NULL);
    This query will display all the parent tables and their primary key columns.Now my problem is that how to modify this query to also display the foreign key column name of the child table.
    I want the query result in the following format.The query should display the following columns.1)child table's name,2)child table's foreign key column name,3)the corresponding parent table's name,4)the parent table's primary key column name(which is the foreign key in the child table).
    For Example I want the output as follows...
    TAKE THE CASE OF SCOTT.EMP(AS INPUT TO YOUR QUERY)
    CHILD_TABLE CHILD_COLUMN PARENT_TABLE PARENT_COLUMN
    EMP DEPTNO DEPT DEPTNO
    In this result I hv used alias name for the columns.The query should display this only for the foreign keys in the child table.In the query which I sent to you earlier will give the parent table and the parent column names,But I also want to append the child table and child column names there.
    any help on how to tackle would be appreciated.

    Try this query
    SELECT c.table_name child_table,
         c.column_name child_column,
         p.table_name parent_table,
         p.column_name parent_column
    FROM user_constraints a,user_constraints b,user_cons_columns c,
         user_cons_columns p
    WHERE a.r_constraint_name=b.constraint_name and
          a.constraint_name=c.constraint_name and
          b.constraint_name=p.constraint_name and
          c.position=p.position
    ORDER BY c.constraint_name,c.position
    Anwar

  • When I run the same query for the second time it's faster, I want to reset this behavior

    I am running a query in oracle 11g select A from B where C = ':D' B has millions of records.
    The first time i run it it takes about 30 seconds, the second time i run the query it takes about 1 second.
    Obviously it's caching something and i want it to stop that, each time i run the query i want it to take 30s - just like it was running for the first time.
    The reason I want to reset this is because for testing purposes I want to measure this query at the very first time.
    Please help.
    Thanks & Best Regards,
    Dark

    user9359353 wrote:
    I am running a query in oracle 11g select A from B where C = ':D' B has millions of records.
    The first time i run it it takes about 30 seconds, the second time i run the query it takes about 1 second.
    Obviously it's caching something and i want it to stop that, each time i run the query i want it to take 30s - just like it was running for the first time.
    The reason I want to reset this is because for testing purposes I want to measure this query at the very first time.
    Please help.
    Thanks & Best Regards,
    Dark
    No - you do NOT want to do that. Not if you want to get results that really represent how that query will work in reality.
    See these two AskTom blogs where he discusses the reasons for NOT doing this in detail.
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:7413988573867
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:311990400346061304

  • How to  Export/Import "report for the query" to another company

    Hello,
    I do this:
    1.create query in SQL analizer
    2.copy paste into SBO query generator and save
    3.create report for the query
    Then, How to Export/Import "report for the query" to another company ?
    Thanks for your HELP.

    Look for SAP Note number 600813
    That's the note Adele means, I guess.
    <b>Edit (@13:18)</b>
    The direct link:
    https://websmp101.sap-ag.de/~sapidb/012006153200000183292003E.ITF
    ---- Replace *SOURCE* with the source database name.
    ---- Replace *DEST* with the destination database name.
    insert into [*DEST*].[dbo].[RDOC]
    select [*SOURCE*].[dbo].[RDOC].*
    from
    [*SOURCE*].[dbo].[RDOC],[*DEST*].[dbo].[cinf],[*SOURCE*].[dbo].[cinf]
    where [*DEST*].[dbo].[cinf].[lawsset]=[*SOURCE*].[dbo].[cinf].[lawsset]and [*DEST*].[dbo].[cinf].[version]=[*SOURCE*].[dbo].[cinf].[version] and [*SOURCE*].[dbo].[RDOC].[Doccode]NOT IN (SELECT Doccode from [*DEST*].[dbo].[RDOC])
    insert into [*DEST*].[dbo].[RITM]
    select [*SOURCE*].[dbo].[RITM].*
    from [*SOURCE*].[dbo].[RITM],[*DEST*].[dbo].[cinf],[*SOURCE*].[dbo].[cinf] where [*SOURCE*].[dbo].[RITM].[Doccode] NOT IN (select Doccode from [*DEST*].[dbo].[RITM])AND [*SOURCE*].[dbo].[RITM].[Doccode]IN (SELECT Doccode from [*DEST*].[dbo].[RDOC])
    Hope it helps...
    Grtz, Rowdy

Maybe you are looking for

  • Java issue with web analysis

    Hi, Web analysis is taking too long to start on client machines. I had this issue a couple of years ago with java 1.4.10. hyperion came back with a solution to increase the memory java uses on both the server and the client. »Xms128m -Xmx256m -Xss2m

  • Problem when writing a value to an enum

    Hi together, I'm facing a problem when using an enum in my state machine. From time to time, the value (which represents the next state) which comes from the shiftregister, is not stored correctly into my enumvariable.When I probe point "1", a differ

  • ABAP Webdynpro: Capturing keystroke event

    Hello, There is a potential requirement to capture a keystroke event from a SAP standard webdynpro text box and provide a character count in a custom UI display text box on number of characters remaining. From initial research - it looks like this ma

  • Portal Drive Authentication Issue

    Hi Folks, I have installed the Portal Drive on my Desktop. It works quite good except the authentication of my user-id. This means, whenever I connect to a KM folder that can be accessed by "Everyone", everything works well. All functionalities are p

  • "add to" button not showing on itunes 11 for iphone

    i have no "add to" button showing in the in this iphone page on itunes 11