Help required in refining a query

I have a sql query :
select C1 AS No_Of_Completed_WOs, C2 as Wos_with_Soft_Fail, (C1-C2) as Completed_Wos,C3 as Failed_Wos,C4 as TimedOut_Wos from (select (CASE WHEN TBL_WRK_ORD.EXTSYS_ID IS NULL THEN '<NULL>'
ELSE TBL_WRK_ORD.EXTSYS_ID END),
count(case when WO_STAT=104 AND XACTION_TYPE like '%Completion%' then WO_STAT end ) as C1,
count(case when WO_STAT=104 AND XACTION_TYPE like '%Soft Error%' then WO_STAT end ) AS C2,
count(case when WO_STAT=253 then WO_STAT end ) AS C3,
count(case when WO_STAT=251 then WO_STAT end ) AS C4
from TBL_WRK_ORD,TBL_WO_EVENT_QUEUE WHERE TBL_WRK_ORD.WO_ID=TBL_WO_EVENT_QUEUE.WO_ID group by TBL_WRK_ORD.EXTSYS_ID)
The query basically maintains a separate counter for each of the qualifying condition.
C1 : if the WO_STAT is 104 and XACTION_TYPE is '%Completion%'
C2 : if the WO_STAT is 104 and XACTION_TYPE is '%Soft Error%'
C3 : if the WO_STAT is 253
C4 : if the WO_STAT is 251.
Now, the requirement is that we need to fetch distinct records, based on which the summation will be carried upon.
I was not able to incorporate the "distinct" logic in the above query.
Required help in this regards, as how to fetch distinct records and use it in the summation logic.
A quick help would be appreciated and thankful.
Regards
RAT.
Edited by: user9546298 on Feb 24, 2010 6:36 AM
Edited by: user9546298 on Feb 24, 2010 7:06 AM

Here is the sample data :
{code }
Table : TBL_WRK_ORD
WO_ID SCHED_DTS WO_STAT
EXTSYS_ID
A00000001-QRY_ISUP_SERVICE_L 20091126 03:28:02 103
MRK
A00000002-S3 20091201 02:42:34 255
MRK
A00000003-A4 20091201 02:50:28 253
A00000006-ADD1 20091202 05:37:45 104
A00000004-ADD1 20091201 03:40:39 104
A00000005-DNH1 20091202 05:12:06 253
6 rows selected.
Table : TBL_WO_EVENT_QUEUE
WO_ID XACTION_TYPE
A00000001-QRY_ISUP_SERVICE_L WO Accept
A00000001-QRY_ISUP_SERVICE_L WO Startup
A00000001-QRY_ISUP_SERVICE_L WO Completion
A00000002-S3 WO Accept
A00000003-A4 WO Accept
A00000003-A4 WO Startup
A00000003-A4 WO Rollback
A00000003-A4 WO Failure
A00000005-DNH1 WO Rollback
A00000005-DNH1 WO Failure
A00000006-ADD1 WO Accept
A00000006-ADD1 WO Startup
A00000004-ADD1 WO Accept
A00000004-ADD1 WO Startup
A00000004-ADD1 WO Completion
A00000005-DNH1 WO Accept
A00000005-DNH1 WO Startup
A00000006-ADD1 WO Completion
Current output :
NO_OF_COMPLETED_WOS WOS_WITH_SOFT_FAIL COMPLETED_WOS FAILED_WOS TIMEDOUT_WOS
2 0 2 8 0
0 0 0 0 0
Here, as you can see above that the result has duplicates, which caused the counters to show wrong result.
Now, the query should filter based on given criteria and produce the count of the filtered rows.
But doing so, should consider distinct rows for counting.
Also, just placing distinct at counting logic [ pasted by you ] didnot work. I tried it out, but in vain.
Regards
RAT.
Edited by: user9546298 on Feb 24, 2010 7:09 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Urgent Help required in Tunning this query

    I have table ACCOUNT SPONSOR HOMESTORE ASH with more than 30 million rows.
    My batch daily need to update or insert into this table from a temporary table TEMP_HSTRALCT. The data for temporary table is populated by below query which selects from two tables TRANSACTION POINTS and REDEMPTIONS.However both these tables are partitioned on date time and is run daily and this is running for hours.
    Can anyone please help me on tuning this query
    INSERT INTO temp_hstralct
    (tmp_n_collector_account_num, tmp_v_location_id,
    tmp_v_sponsor_id, tmp_v_source_file_name,
    tmp_n_psc_insert_ind, tmp_n_psc_update_ind,
    tmp_n_transaction_amount, tmp_n_transaction_points,
    tmp_n_acc_insert_ind, tmp_n_ash_insert_ind,
    tmp_n_col_insert_ind, tmp_n_check_digit,
    tmp_n_collector_issue_num, tmp_n_csl_insert_ind,
    tmp_v_offer_code, tmp_n_psa_insert_ind)
    SELECT DISTINCT trp_n_collector_account_num account_num,
    trp_v_location_id location_id,
    trp_v_sponsor_id sponsor_id,
    trp_c_creation_user batch_id, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0
    FROM transaction_points, ACCOUNT, locations_master,homestores
    WHERE hsr_v_accrual_allowed = 'Y'
    AND trp_n_collector_account_num = ACCOUNT.acc_n_account_num(+)
    AND ( ( ( ACCOUNT.acc_v_account_type = 'C'
    OR ACCOUNT.acc_v_account_type IS NULL
    AND hsr_v_b2c_accounts = 'Y'
    OR ( ACCOUNT.acc_v_account_type = 'B'
    AND hsr_v_nfb_accounts = 'Y'
    OR ( ACCOUNT.acc_v_account_type = 'H'
    AND hsr_v_hybrid_accounts = 'Y'
    AND trp_d_creation_date_time BETWEEN SYSDATE-3
    AND SYSDATE
    AND trp_v_sponsor_id = 'JSAINSBURY'
    AND trp_v_location_id =
    locations_master.lnm_v_location_id
    AND locations_master.lnm_v_partner_id = 'JSAINSBURY'
    AND ( ( ( (INSTR
    (hsr_v_store_status,
    locations_master.lnm_c_location_status
    ) > 0
    AND (INSTR
    (hsr_v_store_type,
    locations_master.lnm_c_location_type
    ) > 0
    AND hsr_v_homestore_assignment = 'ST'
    OR ( ( locations_master.lnm_c_homestore_ind =
    'Y'
    AND (INSTR
    (hsr_v_store_status,
    locations_master.lnm_c_location_status
    ) > 0
    AND hsr_v_homestore_assignment = 'HS'
    UNION ALL
    SELECT DISTINCT rdm_n_collector_account_num account_num,
    rdm_v_location_id location_id,
    rom_v_supplier_id sponsor_id,
    rdm_c_creation_user batch_id, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0
    FROM redemption_details,
    reward_offer_master,
    ACCOUNT,
    locations_master,
    HOMESTORES
    WHERE hsr_v_redemption_allowed = 'Y'
    AND rdm_n_collector_account_num = ACCOUNT.acc_n_account_num(+)
    AND ( ( ( ACCOUNT.acc_v_account_type = 'C'
    OR ACCOUNT.acc_v_account_type IS NULL
    AND hsr_v_b2c_accounts = 'Y'
    OR ( ACCOUNT.acc_v_account_type = 'B'
    AND hsr_v_nfb_accounts = 'Y'
    OR ( ACCOUNT.acc_v_account_type = 'H'
    AND hsr_v_hybrid_accounts = 'Y'
    AND rdm_d_creation_date_time BETWEEN SYSDATE-3
    AND SYSDATE
    AND rom_v_reward_offer_id = rdm_v_reward_id
    AND rom_v_supplier_id = 'JSAINSBURY'
    AND rdm_v_location_id =
    locations_master.lnm_v_location_id
    AND locations_master.lnm_v_partner_id ='JSAINSBURY'
    AND ( ( ( (INSTR
    (hsr_v_store_status,
    locations_master.lnm_c_location_status
    ) > 0
    AND (INSTR
    (hsr_v_store_type,
    locations_master.lnm_c_location_type
    ) > 0
    AND hsr_v_homestore_assignment = 'ST'
    OR ( ( locations_master.lnm_c_homestore_ind =
    'Y'
    AND (INSTR
    (hsr_v_store_status,
    locations_master.lnm_c_location_status
    ) > 0
    AND hsr_v_homestore_assignment = 'HS'
    );

    I have copied the explain as it is and can you please try pasting in the text pad.Can you let me know whether parallel hint on this will speed up the select queries.
              Plan
              INSERT STATEMENT CHOOSECost: 410,815 Bytes: 2,798,394 Cardinality: 15,395                                                        
                   32 UNION-ALL                                                   
                        15 SORT UNIQUE Cost: 177,626 Bytes: 2,105,592 Cardinality: 11,896                                              
                             14 FILTER                                         
                                  13 HASH JOIN Cost: 177,312 Bytes: 2,105,592 Cardinality: 11,896                                    
                                       2 TABLE ACCESS BY INDEX ROWID LMHOLTP.LOCATIONS_MASTER Cost: 37 Bytes: 23,184 Cardinality: 966                               
                                            1 INDEX RANGE SCAN NON-UNIQUE LMHOLTP.IX_LOCATIONS_MASTER_3 Cost: 3 Cardinality: 1                          
                                       12 FILTER                               
                                            11 HASH JOIN OUTER                          
                                                 8 MERGE JOIN CARTESIAN Cost: 155,948 Bytes: 702,656,660 Cardinality: 4,845,908                     
                                                      3 TABLE ACCESS FULL LMHOLTP.HOMESTORES Cost: 2 Bytes: 104 Cardinality: 1                
                                                      7 BUFFER SORT Cost: 155,946 Bytes: 198,682,228 Cardinality: 4,845,908                
                                                           6 PARTITION RANGE ITERATOR Partition #: 12           
                                                                5 TABLE ACCESS BY LOCAL INDEX ROWID LMHOLTP.TRANSACTION_POINTS Cost: 155,946 Bytes: 198,682,228 Cardinality: 4,845,908 Partition #: 12      
                                                                     4 INDEX RANGE SCAN NON-UNIQUE LMHOLTP.IX_TRANSACTION_POINTS_1 Cost: 24,880 Cardinality: 6,978,108 Partition #: 12
                                                 10 PARTITION RANGE ALL Partition #: 15 Partitions accessed #1 - #5                    
                                                      9 TABLE ACCESS FULL LMHOLTP.ACCOUNT Cost: 6,928 Bytes: 68,495,680 Cardinality: 8,561,960 Partition #: 15 Partitions accessed #1 - #5               
                        31 SORT UNIQUE Cost: 233,189 Bytes: 692,802 Cardinality: 3,499                                              
                             30 FILTER                                         
                                  29 FILTER                                    
                                       28 NESTED LOOPS OUTER                               
                                            24 HASH JOIN Cost: 226,088 Bytes: 664,810 Cardinality: 3,499                          
                                                 16 TABLE ACCESS FULL LMHOLTP.REWARD_OFFER_MASTER Cost: 8 Bytes: 2,280 Cardinality: 114                     
                                                 23 HASH JOIN Cost: 226,079 Bytes: 8,327,280 Cardinality: 48,984                     
                                                      20 TABLE ACCESS BY INDEX ROWID LMHOLTP.LOCATIONS_MASTER Cost: 37 Bytes: 432 Cardinality: 18                
                                                           19 NESTED LOOPS Cost: 39 Bytes: 2,304 Cardinality: 18           
                                                                17 TABLE ACCESS FULL LMHOLTP.HOMESTORES Cost: 2 Bytes: 104 Cardinality: 1      
                                                                18 INDEX RANGE SCAN NON-UNIQUE LMHOLTP.IX_LOCATIONS_MASTER_3 Cost: 3 Cardinality: 966      
                                                      22 PARTITION RANGE ITERATOR Partition #: 28                
                                                           21 TABLE ACCESS FULL LMHOLTP.REDEMPTION_DETAILS Cost: 226,019 Bytes: 261,636,270 Cardinality: 6,229,435 Partition #: 28           
                                            27 PARTITION RANGE ITERATOR Partition #: 30                          
                                                 26 TABLE ACCESS BY LOCAL INDEX ROWID LMHOLTP.ACCOUNT Cost: 2 Bytes: 8 Cardinality: 1 Partition #: 30                     
                                                      25 INDEX UNIQUE SCAN UNIQUE LMHOLTP.CO_PK_ACCOUNT Cost: 1 Cardinality: 1 Partition #: 30

  • Help required in writing a query

    hi
    Consider a table (ShogenValue) with following data:
    Model_Id header_id Serial_no shogen_no si_val
    4329 1 40001 A0001 1
    4329 1 40001 B0001 2
    4329 1 50300 B0001 3
    4329 1 40001 C0001 4
    4329 1 50300 C0001 5
    4329 1 60001 C0001 6
    Select
         si_val
    From
         ShogenValue
    Where
    model_id = 4329
    And
         header_id = 1
    And
    serial_no = '60001'
    Is it possible to write a modified version of above query which will bring the following result:
    Model_Id header_id Serial_no shogen_no si_val
    4329 1 40001 A0001 1
    4329 1 50300 B0001 3
    4329 1 60001 C0001 6
    Meaning if a record exists for a particular shogen_no (Shogen_no C0001 has value corrosponding to '60001' in above query), pick it up, if it
    does not exist (Shogen_no B0001 does not have value corrosponding to '60001' in above case) then pick a record with one level less serial number ('50300' in above case) and so on.
    Thanx
    Regards
    Omer Imtiaz

    This should help, although it will probably not perform. Try it and see what the plan for it is.
    SELECT
    FROM
      shogenvalue sv,
      (SELECT
        max(serial_no) serial_no_max,
        shogen_no
      FROM
        shogenvalue
      WHERE
        model_id = 4329
        AND header_id = 1
        AND serial_no <= '60001'
      GROUP BY
        shogen_no
      ) svm
    WHERE
      sv.serial_no = svm.serial_no_max
      AND sv.shogen_no = svm.shogen_no
    ;HTH,
    Lennert

  • Help required in optimizing the query response time

    Hi,
    I am working on a application which uses a jdbc thin client. My requirement is to select all the table rows in one table and use the column values to select data in another table in another database.
    The first table can have maximum of 6 million rows but the second table rows will be around 9000.
    My first query is returning within 30-40 milliseconds when the table is having 200000 rows. But when I am iterating the result set and query the second table the query is taking around 4 millisecond for each query.
    the second query selection criteria is to find the value in the range .
    for example my_table ( varchar2 column1, varchar2 start_range, varchar2 end_range);
    My first query returns a result which then will be used to select using the following query
    select column1 from my_table where start_range < my_value and end_range> my_value;
    I have created an index on start_range and end_range. this query is taking around 4 millisseconds which I think is too much.
    I am using a preparedStatement for the second query loop.
    Can some one suggest me how I can improve the query response time?
    Regards,
    Shyam

    Try the code below.
    Pre-requistee: you should know how to pass ARRAY objects to oracle and receive resultsets from java. There are 1000s of samples available on net.
    I have written a sample db code for the same interraction.
    Procedure get_list takes a array input from java and returns the record set back to java. You can change the tablenames and the creteria.
    Good luck.
    DROP TYPE idlist;
    CREATE OR REPLACE TYPE idlist AS TABLE OF NUMBER;
    CREATE OR REPLACE PACKAGE mypkg1
    AS
       PROCEDURE get_list (myval_list idlist, orefcur OUT sys_refcursor);
    END mypkg1;
    CREATE OR REPLACE PACKAGE BODY mypkg1
    AS
       PROCEDURE get_list (myval_list idlist, orefcur OUT sys_refcursor)
       AS
          ctr   NUMBER;
       BEGIN
          DBMS_OUTPUT.put_line (myval_list.COUNT);
          FOR x IN (SELECT object_name, object_id, myvalue
                      FROM user_objects a,
                           (SELECT myval_list (ROWNUM + 1) myvalue
                              FROM TABLE (myval_list)) b
                     WHERE a.object_id < b.myvalue)
          LOOP
             DBMS_OUTPUT.put_line (   x.object_name
                                   || ' - '
                                   || x.object_id
                                   || ' - '
                                   || x.myvalue
          END LOOP;
       END;
    END mypkg1;
    [pre]
    Testing the code above. Make sure dbms output is ON.
    [pre]
    DECLARE
       a      idlist;
       refc   sys_refcursor;
       c number;
    BEGIN
       SELECT x.nu
       BULK COLLECT INTO a
         FROM (SELECT 5000 nu
                 FROM DUAL) x;
       mypkg1.get_list (a, refc);
    END;
    [pre]
    Vishal V.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Help required in writing the query

    I have the following level accounts
    10000
    11000
    11100
    11101
    11200
    11201
    12000
    12100
    12101
    12102
    12103
    20000
    21000
    21100
    21101
    22000
    22101
    21200
    21201
    I have to take the amount of the child account and sum it to the parent account as below:
    11100 = 11101 + 11102 - 11103+.........
    11000 = 11100 + 11200 + 11300+.........
    10000 = 11000 + 12000 + 13000+.........
    21100 = 21101 + 21102 - 21103+.........
    21000 = 21100 + 21200 + 21300+.........
    20000 = 21000 + 22000 + 23000+.........
    Please help...
    Thanks in advance.

    SQL> with t as (
      2             select 10000 ACCOUNT, NULL BEG_BAL, NULL END_BAL from dual union all
      3             select 11000,NULL,NULL from dual union all
      4             select 11100,NULL,NULL from dual union all
      5             select 11101,1750.00,4150.00 from dual union all
      6             select 11102,1550.00,3150.00 from dual union all
      7             select 11103,1650.00,3200.00 from dual union all
      8             select 11200,NULL,NULL from dual union all
      9             select 11201,800.00,1250.00 from dual union all
    10             select 11202,1550.00,3150.00 from dual union all
    11             select 12000,NULL,NULL from dual union all
    12             select 12100,NULL,NULL from dual union all
    13             select 12101,1200.00,5000.00 from dual union all
    14             select 12102,1500.00,3000.00 from dual union all
    15             select 12103,1550.00,2750.00 from dual union all
    16             select 20000,NULL,NULL from dual union all
    17             select 21000,NULL,NULL from dual union all
    18             select 21100,NULL,NULL from dual union all
    19             select 21101,2000.00,6500.00 from dual union all
    20             select 21102,1500.00,3500.00 from dual union all
    21             select 21103,1750.00,3550.00 from dual union all
    22             select 22000,NULL,NULL from dual union all
    23             select 22100,NULL,NULL from dual union all
    24             select 22101,1550.00,3550.00 from dual union all
    25             select 22102,2550.00,5550.00 from dual union all
    26             select 21200,NULL,NULL from dual union all
    27             select 21201,2550.00,6500.00 from dual union all
    28             select 21202,3550.00,7500.00 from dual
    29            )
    30  select  account,
    31          beg_bal,
    32          end_bal,
    33          sum(beg_bal) over(order by account range between current row and grouping_window follow
    ing) group_beg_bal,
    34          sum(end_bal) over(order by account range between current row and grouping_window follow
    ing) group_end_bal
    35    from  (
    36           select  t.*,
    37                   case
    38                     when account / 10000 = trunc(account / 10000) then 9999
    39                     when account / 1000 = trunc(account / 1000) then 999
    40                     when account / 100 = trunc(account / 100) then 99
    41                     when account / 10 = trunc(account / 10) then 9
    42                     else 0
    43                   end grouping_window
    44             from  t
    45          )
    46  order by account
    47  /
       ACCOUNT    BEG_BAL    END_BAL GROUP_BEG_BAL GROUP_END_BAL
         10000                               11550         25650
         11000                                7300         14900
         11100                                4950         10500
         11101       1750       4150          1750          4150
         11102       1550       3150          1550          3150
         11103       1650       3200          1650          3200
         11200                                2350          4400
         11201        800       1250           800          1250
         11202       1550       3150          1550          3150
         12000                                4250         10750
         12100                                4250         10750
       ACCOUNT    BEG_BAL    END_BAL GROUP_BEG_BAL GROUP_END_BAL
         12101       1200       5000          1200          5000
         12102       1500       3000          1500          3000
         12103       1550       2750          1550          2750
         20000                               15450         36650
         21000                               11350         27550
         21100                                5250         13550
         21101       2000       6500          2000          6500
         21102       1500       3500          1500          3500
         21103       1750       3550          1750          3550
         21200                                6100         14000
         21201       2550       6500          2550          6500
       ACCOUNT    BEG_BAL    END_BAL GROUP_BEG_BAL GROUP_END_BAL
         21202       3550       7500          3550          7500
         22000                                4100          9100
         22100                                4100          9100
         22101       1550       3550          1550          3550
         22102       2550       5550          2550          5550
    27 rows selected.
    SQL> SY.

  • Help required regarding tunning the query mentioned

    HI all ,
    Query mentioned below takes around 1 hr to complete . It's being used by the autoconfig kindly me in tunning it ..
    QUery :
    UPDATE WF_ITEM_ATTRIBUTE_VALUES WIAV SET WIAV.TEXT_VALUE = REPLACE(WIAV.TEXT_VALUE,:B1,:B2)
    WHERE (WIAV.ITEM_TYPE, WIAV.NAME) = (SELECT WIA.ITEM_TYPE, WIA.NAME
    FROM WF_ITEM_ATTRIBUTES WIA WHERE WIA.TYPE = 'URL'
    AND WIA.ITEM_TYPE = WIAV.ITEM_TYPE
    AND WIA.NAME = WIAV.NAME)
    AND WIAV.TEXT_VALUE IS NOT NULL
    AND INSTR(WIAV.TEXT_VALUE
    , :B1) > 0
    Plan :*
    <pre>
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | UPDATE STATEMENT | | 453 | 14496 | 284K|
    | 1 | UPDATE | WF_ITEM_ATTRIBUTE_VALUES | | | |
    |* 2 | FILTER | | | | |
    |* 3 | TABLE ACCESS FULL | WF_ITEM_ATTRIBUTE_VALUES | 453 | 14496 | 282K|
    |* 4 | TABLE ACCESS BY INDEX ROWID| WF_ITEM_ATTRIBUTES | 1 | 33 | 2 |
    |* 5 | INDEX UNIQUE SCAN | WF_ITEM_ATTRIBUTES_PK | 1 | | 1 |
    Predicate Information (identified by operation id):
    2 - filter(("SYS_ALIAS_2"."ITEM_TYPE","SYS_ALIAS_2"."NAME")= (SELECT /*+ */
    "WIA"."ITEM_TYPE","WIA"."NAME" FROM "APPLSYS"."WF_ITEM_ATTRIBUTES" "WIA" WHERE
    "WIA"."NAME"=:B1 AND "WIA"."ITEM_TYPE"=:B2 AND "WIA"."TYPE"='URL'))
    3 - filter("SYS_ALIAS_2"."TEXT_VALUE" IS NOT NULL AND
    INSTR("SYS_ALIAS_2"."TEXT_VALUE",:Z)>0)
    4 - filter("WIA"."TYPE"='URL')
    5 - access("WIA"."ITEM_TYPE"=:B1 AND "WIA"."NAME"=:B2)
    </pre>
    Index :*
    <pre>
    INDEX_NAME COLUMN_NAME
    APPLSYS WF_ITEM_ATTRIBUTE_VALUES_PK 1 ITEM_TYPE
    2 ITEM_KEY
    3 NAME
    </pre>
    regds
    Rahul
    Edited by: RahulG on Jan 2, 2009 10:47 PM
    Edited by: RahulG on Jan 2, 2009 10:48 PM

    RahulG wrote:
    HI all ,
    Query mentioned below takes around 1 hr to complete . It's being used by the autoconfig kindly me in tunning it ..
    A few notes:
    1. Your query is using bind variables. If you're already on 9i or later (probably 9iR2 according to plan output), this statement will be subject to bind variable peeking and therefore the output of EXPLAIN PLAN is only of limited use, since the actual execution plan might be different and/or might be based on different cardinality estimates based on the actual bind values peeked at hard parse time. You can use the V$SQL_PLAN view to get the actual execution plan(s) if the statement is still cached in the shared pool, from 10g on DBMS_XPLAN.DISPLAY_CURSOR is available for that purpose.
    2. The execution plan posted suggests that only 453 rows will correspond to the filter criteria (but, as mentioned in 1. is based on an unknown bind variable value when using EXPLAIN PLAN), and probably therefore the optimizer didn't unnest the subquery but runs this as recursive FILTER query potentially for each row passing the filter criteria on the driving table WF_ITEM_ATTRIBUTE_VALUES. Depending on the actual number of rows this might be inefficient, and unnesting the subquery and turning it into a join might be more appropriate. This might accomplished e.g. by providing more representative statistics to the optimizer (are the statistics up-to-date?).
    Although you can't change the SQL you could try this manually by using the UNNEST hint to see if it makes any difference in the execution plan (and run time):
    WHERE (WIAV.ITEM_TYPE, WIAV.NAME) = (SELECT /*+ UNNEST */ WIA.ITEM_TYPE, WIA.NAME
    ...3. The composite index WF_ITEM_ATTRIBUTE_VALUES_PK can only be used on the first column ITEM_TYPE for effective index access, the NAME column would have to be used as filter on all index leaf blocks that would be found using a range scan on ITEM_TYPE. This might be quite inefficient, and/or might lead to a lot of rows/blocks that need to be visited in the table using this index access path.
    4. You could try to trace the execution by enabling extended SQL trace, e.g. using the (undocumented) DBMS_SUPPORT package in 9i. Running the "tkprof" utility on the generated trace file tells you the actual row source cardinalities (which can then be compared to the estimates of the optimizer) and - if the "waits" have been enabled - what your statement has waited for most.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • T-SQL help require to construct a query to sum on varchar column

    Guys,
    I have a column varchar(400) wherein currency_amount is stored. I need to sum currencyamount however getting the error like  Arithmetic overflow error converting varchar to data type numeric.
    Any suggestion? it has some values  which are having 37 digits after decimal. Might be this is the possible reason.
    Few Ex. .240189558129349189976534590012169112856, .312064488126471335301440042584800148951
    This is the query i am trying
    select sum(convert(decimal(38,20),columnname))
    FROM tablename 

    Did you try converting to float? Also, why do you have such high number of digits if you're talking about currency amounts? Normally, 2 digits is enough for currency.
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • Help required in creating a QUERY!!!

    hi my name is johnny. I am new to this forums.
    My question is
    "There are 4 players in a team and that team played 4 matches. The scores for player1: 34,44,23,9. player2: 12,15,62,40. player3: 54,65,34,82. player4: 77,53,69,88. in four inning in four matches respectively. So my question is that i want highest score of each player in a column in the desceding order."
    Sample output:
    player_name test1 test2 test3 test4 highest_score
    player4 77 53 69 88 88
    player3 54 65 34 82 82
    player2 12 15 62 40 62
    player1 34 44 23 09 44

    Can you tell us how your data is stored in the database. I mean what is the table structure of the table that stores the data for all the inings and scores for all the players?
    Faisal.

  • Need help in refining the query

    Hello Experts,
    Need your help in refining the query further more.
    table structure 
    Mskey  Col A Col B
    1   empno [20141127-20151128]1234
    1   empno [20151201-99991231]232544
    1   salutation [20141127-99991231]Mrs
    1   salutation [20151127-99991231]Mr
    2   empno [20141127-20151128]1234
    2   empno [20151201-99991231]232544
    2   salutation [20141127-99991231]Mrs
    2   salutation [20151127-99991231]Mr
    My requirement is to find the list of overlapping records based on the dates
    user details may be varying from time to time as new data would be pushed through HR systems to identity store via an interface.
    The job is getting failed whenever there is any overlapping with dates. So we proactively decided to schedule a job in this regards which runs weekly and would let us know for which and all the users there is overlapping dates are there, so that we can send the list to HR team for pushing new data.
    Overlapping Issue Example:
    The users employee id for an year it is 1234 and later he moved to another department and his employee id got changed and it became 2345 remaining all details are same. So the HR systems send the data for this user as empno - [20141127-20151128]1234 and empno - [20151201-99991231]232544
    it means from 20141127 to 20151128 his employee no is 1234 and from 20151201 to 99991231 his employee would be 2345.
    This is a correct case and the tool would accept this data.
    the below cases are invald
    Case 1: 1 salutation [20141127-99991231]Mrs 1 salutation [20151127-99991231]Mr
    Case 2: 2 salutation [20141127-99991231]Mrs 2 salutation [20141127-99991231]Mr
    So we wanted to find these overlapping records from tables.
    My Query:
    I am able to successfully write query for the case 2 type but unable to write for case1.
    select id,colA
    count(left(ColB,CHARINDEX(']',ColB))) as 'Count'
    from tblA with (nolock)
    where id in (Select distinct id from tblb with (nolock))
    group by id, cola,left(ColB,CHARINDEX(']',ColB))
    having count(left(ColB,CHARINDEX(']',ColB)))>1

    Finally got the required answer with the below query
    WITH Cte AS
    SELECT ID,ColA,ColB,ROW_NUMBER() OVER(ORDER BY (SELECT 1)) AS RN,
    CAST(SUBSTRING(ColB,2,CHARINDEX('-',ColB)-2) AS DATE) AS StartDT,
    CAST(SUBSTRING(ColB,CHARINDEX('-',ColB)+1,8) AS DATE)  AS EndDT  FROM TblA
    SELECT c1.ID, c1.ColA,c1.ColB
    FROM Cte c1 JOIN Cte c2
    ON c1.RN != c2.RN
    AND c1.ID=c2.ID
    AND c1.ColA=c2.ColA
    AND (c1.StartDT BETWEEN c2.StartDT AND c2.EndDT OR c2.StartDT BETWEEN c1.StartDT AND c1.EndDT )

  • Query help required to link two fields

    Hi all,
    I have made an query as under :
    SELECT T2.Period, T0.dept, T0.empID, T0.firstName, T0.lastName, T1.U_ebasic, T1.U_ehra, T1.U_etrspt, T1.U_ecola, T1.U_emeins, T1.U_education, T1.U_grosssal,T1.U_totduc, T1.U_oadd, T1.U_netsal, T1.U_bank, T1.U_branch, T1.U_accno FROM OHEM T0 , [dbo].[@PAYROLL_PR_DETAIL]  T1, [dbo].[@PAYROLL_PROLL_HEAD]  T2 where t2.docentry=t1.docentry and t1.U_ecode=t0.empid
    Now I want that the Department Full NAME as mentioned in the Human Resource screen for that employee should come. Apart from it I also want to link a new field in this query user_code from OUSR table for each employee.
    Can you please help me to make this query.
    Regards,
    kamlesh

    Dear Gordon,
    After rectifiying the spelling mistake I used the following query as under
    SELECT T2.Period, T0.dept, T3.Name, T0.empID, T0.firstName, T0.lastName, T4.USER_CODE,T1.U_ebasic, T1.U_ehra, T1.U_etrspt, T1.U_ecola, T1.U_emeins, T1.U_education, T1.U_grosssal,T1.U_totduc, T1.U_oadd, T1.U_netsal, T1.U_bank, T1.U_branch, T1.U_accno
    FROM dbo.OHEM T0
    INNER JOIN dbo.OUDP T3 ON T3.Code = T0.dept
    INNER JOIN dbo.OUSR T4 ON T4.INTERNAL_K = T0.userId
    INNER JOIN dbo.@PAYROLL_PR_DETAIL T1 ON t1.U_ecode=t0.empid
    INNER JOIN dbo.@PAYROLL_PROLL_HEAD T2 ON t2.docentry=t1.docentry
    but now the syntax error is coming as - 'Incorrect syntax near '@PAYROLL_PR_DETAIL'
    (SEWSY) (s) could not be prepared
    Please guide.
    Regards,
    Kamlesh

  • Urgent help required: Query regarding LC Variables

    Hi All
    Sometime earlier I was working on a performance issue raised by a customer. It was shell script that was taking almost 8-9 hrs to complete. During my research I came across a fact that there were some variables which were not set, the LC variables were impacting the sort funnel operations because of which the script was taking a long time to execute.
    I asked them to export the following commands, after which the program went on smoothly and finished in a couple of mins:
    export LC_COLLATE=en_US.ISO8859-1
    export LC_MESSAGES=C
    export LC_MONETARY=en_US.ISO8859-1
    export LC_MONETARY=en_US.ISO8859-1
    export HZ=100
    export LC_CTYPE=en_US.ISO8859-1
    export LANG=en_US.UTF-8
    Later I did recover that setting the LC_COLLATE to C, is not helping and the program was again taking a lot of time. Few questions that I want to ask are:
    1. Can someone please tell me, what each of these variable mean and how these values make a difference.
    2. When I exported LC_COLLATE=en_US.ISO8859-1, it worked fine, but when i tried with the defalut value LC_COLLATE=C, then why the program didnt work.
    As this issue is still going on, hence I would request All to provide their valuable inputs and let me know as much as possible.
    Appreciate your help in this regard.
    Thanks
    Amit
    Hi All
    A new development in this regard. The customer has send us a screen shot in which they were trying to export the locale variable using the commands which I have pasted above. I can see in the screen shot that while exporting LC_COLLATE and LC_TYPE, they get a message that ""ksh: export: couldn't set locale correctly"".
    Request everyone to please give their inputs as it's a bit urgent.
    Thanks for all the help in advance.
    Thanks
    Amit
    Some help required please...
    Edited by: amitsinhaengg on Jul 22, 2009 2:03 AM
    Edited by: amitsinhaengg on Jul 22, 2009 2:06 AM

    LC_CTYPE
    Controls the behavior of character handling functions.
    LC_TIME
    Specifies date and time formats, including month names, days of the week, and common full and abbreviated representations.
    LC_MONETARY
    Specifies monetary formats, including the currency symbol for the locale, thousands separator, sign position, the number of fractional digits, and so forth.
    LC_NUMERIC
    Specifies the decimal delimiter (or radix character), the thousands separator, and the grouping.
    LC_COLLATE
    Specifies a collation order and regular expression definition for the locale.
    LC_MESSAGES
    Specifies the language in which the localized messages are written, and affirmative and negative responses of the locale (yes and no strings and expressions).
    You can use command
    # locale -k LC_CTYPE
    to see more detail about each type.

  • Help Required(Rewriting the query to reduce steps)

    With and Without Group ID,I am populating a value into a column,Can anyone please help to write the same query in an other way.This is a sample column.Likewise,there are 5 more columns to be populated.So that I have to write 2 left outer joins for a single column with a little difference.
    SELECT
    CASE
         WHEN T6.ACTUAL_FUNCTION IS NOT NULL
         THEN T6.ACTUAL_FUNCTION
         WHEN T10.ACTUAL_FUNCTION IS NOT NULL
         THEN T10.ACTUAL_FUCNTION
              ELSE T5.ACTUAL_FUCNTION
    END AF_NOM_PRE_GTEES
    FROM
    ABC_WT17 T1
         INNER JOIN
         ABC_CUSTOMER_WT01 T3
         ON T1.ORIGINAL_SDS_PARTY_IDR=T3.ORIGINAL_SDS_PARTY_IDR
         AND T1.IDR_TYPE_CODE=T3.IDR_TYPE_CODE
         LEFT OUTER JOIN /* This is the condition with group ID*/
         RESIDUAL_CONTROL T6
         ON
         T1.NOM_PRE_GTEES = T6.VALUE_MAX
         OR
         T1.NOM_PRE_GTEES > T6.VALUE_GREATER_THAN
         AND
         T1.NOM_PRE_GTEES < T6.VALUE_MAX
         AND
    _     T1.GROUP_ID = T6.GROUP_ID_
         AND
         T6.FALLBACK_IND = ‘N’
    LEFT OUTER JOIN /* this is the condition without Group ID*/
         RESIDUAL_CONTROL T10
         ON
         T1.NOM_PRE_GTEES = T10.VALUE_MAX
         OR
         T1.NOM_PRE_GTEES > T10.VALUE_GREATER_THAN
         AND
         T1.NOM_PRE_GTEES < T10.VALUE_MAX
         AND
         T10.FALLBACK_IND = ‘N’
         CROSS JOIN
         RESIDUAL_CONTROL T5
         ON T5.FALLBACK_IND = ‘Y’
    Thanks in advance.

    KVB wrote:
    With and Without Group ID,I am populating a value into a column,Can anyone please help to write the same query in an other way.This is a sample column.Likewise,there are 5 more columns to be populated.So that I have to write 2 left outer joins for a single column with a little difference.
    SELECT
    CASE
         WHEN T6.ACTUAL_FUNCTION IS NOT NULL
         THEN T6.ACTUAL_FUNCTION
         WHEN T10.ACTUAL_FUNCTION IS NOT NULL
         THEN T10.ACTUAL_FUCNTION
              ELSE T5.ACTUAL_FUCNTION
    END AF_NOM_PRE_GTEES
    FROM
    ABC_WT17 T1
         INNER JOIN
         ABC_CUSTOMER_WT01 T3
         ON T1.ORIGINAL_SDS_PARTY_IDR=T3.ORIGINAL_SDS_PARTY_IDR
         AND T1.IDR_TYPE_CODE=T3.IDR_TYPE_CODE
         LEFT OUTER JOIN /* This is the condition with group ID*/
         RESIDUAL_CONTROL T6
         ON
         T1.NOM_PRE_GTEES = T6.VALUE_MAX
         OR
         T1.NOM_PRE_GTEES > T6.VALUE_GREATER_THAN
         AND
         T1.NOM_PRE_GTEES < T6.VALUE_MAX
         AND
    _     T1.GROUP_ID = T6.GROUP_ID_
         AND
         T6.FALLBACK_IND = ‘N’
    LEFT OUTER JOIN /* this is the condition without Group ID*/
         RESIDUAL_CONTROL T10
         ON
         T1.NOM_PRE_GTEES = T10.VALUE_MAX
         OR
         T1.NOM_PRE_GTEES > T10.VALUE_GREATER_THAN
         AND
         T1.NOM_PRE_GTEES < T10.VALUE_MAX
         AND
         T10.FALLBACK_IND = ‘N’
         CROSS JOIN
         RESIDUAL_CONTROL T5
         ON T5.FALLBACK_IND = ‘Y’
    Thanks in advance.Thread: HOW TO: Post a SQL statement tuning request - template posting
    HOW TO: Post a SQL statement tuning request - template posting

  • Help need to create a query

    I need to fetch records from a table. Please help me to create a query
    The Tablename is Employee. It has the following records
    Department Empname Gender
    Finance Tom Male
    Finance Rick Male
    Finance Stacy Female
    Corporate Tom Male
    Corporate Rob Male
    I want to select the value of the Gender field from the Employee table corresponding to a Department
    If all the values in the Gender field are 'MALE' corresponding to 'finance' in the Department field, the value should be 'MALE'
    If there is a value 'FEMALE', the gender corresponding to the Empname 'TOM' should be considered as the gender

    Tables have rows - not records.
    Your question is a basic SQL language question - which means you do not know the SQL language. This forum is not a classroom for teaching you the SQL language.
    Use the following as the basic outline of how your SQL language statement need to look like for selecting the required from the table:
    SELECT
      <<sql projection goes here>>
    FROM <<table name goes here>>
    WHERE <<filter conditions go here>>
    {code}
    The SQL projection specifies the list of columns the SQL need to return to the caller.
    The filter condition is basic predicates and AND and OR  can be used for multiple predicates.
    Go to http://tahiti.oracle.com and look for the +SQL Reference Guide+ for the Oracle version you are using. The +SELECT+ statement syntax is covered in detail and sample statements are provided.
    And please do not expect this forum to be used as a classroom, or expect this forum to do your homework for a class.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Help needed to optimize the query

    Help needed to optimize the query:
    The requirement is to select the record with max eff_date from HIST_TBL and that max eff_date should be > = '01-Jan-2007'.
    This is having high cost and taking around 15mins to execute.
    Can anyone help to fine-tune this??
       SELECT c.H_SEC,
                    c.S_PAID,
                    c.H_PAID,
                    table_c.EFF_DATE
       FROM    MTCH_TBL c
                    LEFT OUTER JOIN
                       (SELECT b.SEC_ALIAS,
                               b.EFF_DATE,
                               b.INSTANCE
                          FROM HIST_TBL b
                         WHERE b.EFF_DATE =
                                  (SELECT MAX (b2.EFF_DATE)
                                     FROM HIST_TBL b2
                                    WHERE b.SEC_ALIAS = b2.SEC_ALIAS
                                          AND b.INSTANCE =
                                                 b2.INSTANCE
                                          AND b2.EFF_DATE >= '01-Jan-2007')
                               OR b.EFF_DATE IS NULL) table_c
                    ON  table_c.SEC_ALIAS=c.H_SEC
                       AND table_c.INSTANCE = 100;

    To start with, I would avoid scanning HIST_TBL twice.
    Try this
    select c.h_sec
         , c.s_paid
         , c.h_paid
         , table_c.eff_date
      from mtch_tbl c
      left
      join (
              select sec_alias
                   , eff_date
                   , instance
                from (
                        select sec_alias
                             , eff_date
                             , instance
                             , max(eff_date) over(partition by sec_alias, instance) max_eff_date
                          from hist_tbl b
                         where eff_date >= to_date('01-jan-2007', 'dd-mon-yyyy')
                            or eff_date is null
               where eff_date = max_eff_date
                  or eff_date is null
           ) table_c
        on table_c.sec_alias = c.h_sec
       and table_c.instance  = 100;

  • Help required in JDBC to RFC to JDBC

    Hi Guys,
    I have a requirement where I'll query my database which will give me back multiple rows. Each row has a flag which indicates CREATE,DELETE or MODIFY.
    According to the value in these flags, I have to call different BAPI's i.e
    BAPI_CREATE
    BAPI_DELETE
    BAPI_CHANGE
    After calling the BAPI, I need to insert the response back to my database.
    My design logic is
    Inside my BPM, receive my jdbc message and do multimapping transformation with the 3 BAPI types and bundle them.
    After this , I need to use a BLOCK for each STEP where I'll insert the sync send step
    Bundle all the response messages obtained so far and call the jdbc transformation
    Guys I need your help in suggesting any changes in my design
    Am i approaching this situation in the right way???
    Please help me on this guys
    Thanks
    Varun

    Varun,
    Just one thoought over your design....
    Rather than calling BAPI's for every row, just send all rows to the abap proxy or zbapi.
    You can process all your rows at a one time ( which I think would be better design and fast processing) and gather all response from Individual BAPI's for every row  in one internal table and send it back to XI as BAPI's response message.
    In this way you can avoid BPM as well..which will be more faster.
    Let me know if you need more details.
    Nilesh

Maybe you are looking for

  • PNP Selection Screen Modification

    Hi All, Can anyone tell how to remove the payroll period section completely from the pnp selection screen. I tried all the means going to HR Report Category, I couldnt find the perfect category to hide the payroll period selection. It neither allow m

  • Arabic fonts for mac

    Hi- I need to add Arabic fonts to my mac in order to be able to copy and paste from a pdf file to a browser/another application.. iflash! Does anybody know where I can get these from? Thanks Saf

  • What is the reasons when the traplog messages occur

    i have configed two css11506 act as active-backup mode. and there are three real servers supplying web service are through one vip address for clients.when one server is down ,the clients complain that the webpage is opening very slow even not opened

  • How to take away html codes

    Hi Everyone, i am now currently doing a project and my part is to do fourm, i just want to ask abt this problem: If i post a new topic and i enter in html codes that will be very dangerous. So is there anyway to remove the htm codes when i post the n

  • IntegerMap

    how can i implement the interface SortedMap to create a class that named IntegerMap that contains only instances of the class Integer with the technic of a binary tree , i need to implement also Iterator and Comparator than i'll be able to do: Sorted