Help me on Sorting Query

Hi folks
i'm using db version
Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
PL/SQL Release 9.2.0.8.0 - Productioni have a two tables t1 and t2, i want to fetch t2 records in sequence order(if any of record matches with t1, that should be in order of t1 record)
here is sample data
with t1 as (select 2001 as pc_id,1 as seq_Order,101 as nt_id, 20 as ch_id, null as parent_nt_id from dual
          union
          select 2002 as pc_id,2 as seq_Order,101 as nt_id, 21 as ch_id, null as parent_nt_id from dual
          union
          select 2003 as pc_id,3 as seq_Order,101 as nt_id, 22 as ch_id, null as parent_nt_id from dual)
   ,t2 as (select 2004 as pc_id,1 as seq_Order,201 as nt_id, 30 as ch_id, null as parent_nt_id from dual
           union
          select 2005 as pc_id,2 as seq_Order,201 as nt_id, 20 as ch_id, 101 as parent_nt_id from dual
          union
          select 2006 as pc_id,3 as seq_Order,201 as nt_id, 21 as ch_id, 101 as parent_nt_id from dual
          union
          select 2007 as pc_id,4 as seq_Order,201 as nt_id, 22 as ch_id, 101 as parent_nt_id from dual
          union
          select 2008 as pc_id,5 as seq_Order,201 as nt_id, 31 as ch_id, null as parent_nt_id from dual)
select t2.* from t1,t2
where t2.nt_id = 201
and t2.parent_nt_id = t1.nt_id(+)
and t2.ch_id = t1.ch_id(+)
order by t2.seq_orderdata looks like this
pc_id     seq_order     nt_id     ch_id     parent_nt_id
2004     1          201     30     
2005     2          201     20     101
2006     3          201     21     101
2007     4          201     22     101
2008     5          201     31     if i change SEQ_ORDER in t1, let say
t1 as (select 2001 as pc_id,1 as seq_Order,101 as nt_id, 20 as ch_id, null as parent_nt_id from dual
          union
          select 2002 as pc_id,3 as seq_Order,101 as nt_id, 21 as ch_id, null as parent_nt_id from dual --changed order
          union
          select 2003 as pc_id,2 as seq_Order,101 as nt_id, 22 as ch_id, null as parent_nt_id from dual)--changed orderi want to fetch the records from t2 as below
pc_id     seq_order     nt_id     ch_id     parent_nt_id     t1.seq_order
2004     1          201     30     
2005     2          201     20     101     1
2007     3          201     22     101     2          --changed order 4 to 3
2006     4          201     21     101     3          --changed order 3 to 4
2008     5          201     31     how do i achieve this
Changed join condition in where clause
Edited by: user12212962 on Jan 21, 2010 9:12 AM

Now it's a whole different ballgame as your join is broken again and you would need a full outer join to do what you need.
Where did that 2004 in the new row come from? It's 2009 in the original table data you posted.
pc_id seq_order     nt_id    ch_id  parent_nt_id        t1.pc_id
2004  1             201      30     
2005  2             201      20     101                 2001 
2007  4             201      22     101                 2003 
2006  3             201      21     101                 2002 
null  null          201      28     101                 2004--Is this from the first row above from T2?
2008  5             201      31If the 2004 was meant to be 2009, then this could do it:
with t1 as (select 2001 as pc_id,1 as seq_Order,101 as nt_id, 20 as ch_id, null as parent_nt_id from dual union
            select 2002 as pc_id,3 as seq_Order,101 as nt_id, 21 as ch_id, null as parent_nt_id from dual union
            select 2003 as pc_id,2 as seq_Order,101 as nt_id, 22 as ch_id, null as parent_nt_id from dual union
            select 2009 as pc_id,4 as seq_Order,101 as nt_id, 28 as ch_id, null as parent_nt_id from dual)
   ,t2 as (select 2004 as pc_id,1 as seq_Order,201 as nt_id, 30 as ch_id, null as parent_nt_id from dual union
           select 2005 as pc_id,2 as seq_Order,201 as nt_id, 20 as ch_id, 101 as parent_nt_id from dual union
           select 2006 as pc_id,3 as seq_Order,201 as nt_id, 21 as ch_id, 101 as parent_nt_id from dual union
           select 2007 as pc_id,4 as seq_Order,201 as nt_id, 22 as ch_id, 101 as parent_nt_id from dual union
           select 2008 as pc_id,5 as seq_Order,201 as nt_id, 31 as ch_id, null as parent_nt_id from dual)
SELECT pc_id,
       seq_order,
       nt_id,
       ch_id,
       parent_nt_id,
       pc_id_t1
  FROM (SELECT t2.pc_id,
               t2.seq_order,
               nvl(t2.nt_id, t1.nt_id) nt_id,
               nvl(t2.ch_id, t1.ch_id) ch_id,
               nvl(t2.parent_nt_id, t1.nt_id) parent_nt_id,
               t1.pc_id pc_id_t1,
               t1.seq_order seq_order_t1,
               t1.nt_id nt_id_t1,
               MIN(t2.seq_order) over(PARTITION BY t1.nt_id) min_t2_seq
          FROM t2
          FULL OUTER JOIN t1 ON t2.parent_nt_id = t1.nt_id AND t2.ch_id = t1.ch_id
         WHERE nvl(t2.nt_id, 201) = 201) t
ORDER BY NVL2(t.seq_order_t1, min_t2_seq + (t.seq_order_t1 / 10), t.seq_order)Edited by: fsitja on Jan 21, 2010 3:34 PM

Similar Messages

  • Help needed in SORTING query

    I have a table having single column c1 of varchar2(10) and have stored these values in the table.
    A0
    A1
    A01
    A100
    A101
    A102
    B10
    B99
    B100
    B101
    B102
    100
    120
    200
    I need to sort them in the order as given, can someone help please.
    Thanks

    select c
    from (select c, substr(c,1,1) c1, length(c) len, substr(c,2) c2 from xx)
    order by case when ascii(c1) < 65
    then ascii(c1)+100
    else ascii(c1)
    end, len, c2

  • Help tune this monster query please

    Hi, I have a query that runs for a long time. Its a system generated query but I need to improve its performance. I have enough indexes on the tables. Here is the query, its explain plan and the tkprof:
    The QUERY
    SELECT FD.FORM_ID, FD.FIELD_NAME, FD.FIELD_TEXT, FD.OPTION_TEXT, FD.OPTION_TYPE, FD.FIELD_ORDER, FD.LIST_ORDER,
    FD.MULTIPLE_ANSWER, FD.FIELD_INSTANCE, NVL(AD.APPS,0) APPS
    FROM (
        SELECT FIELD_NAME, FIELD_VALUE, INSTANCE, COUNT(0) APPS
        FROM APPLICATION_DATA AD
        WHERE APPLICATION_ID IN (
            SELECT A.APPLICATION_ID
            FROM APPLICATIONS A
            WHERE A.DELETED = 0 AND DECODE(A.TRAY,'Incomplete','Incomplete','Complete') = 'Complete' AND A.JOB_ID IN (
                SELECT JOB_ID
                FROM JOBS J
                WHERE J.ACCOUNT_ID IN (
                    SELECT ACCOUNT_ID
                        FROM AGENCY_ACCOUNTS CONNECT BY ACCOUNT_ID = PRIOR AGENCY_ID START WITH ACCOUNT_ID = J.ACCOUNT_ID ) )                  AND A.ACCOUNT_ID IN (
                        SELECT ACCOUNT_ID
                        FROM AGENCY_ACCOUNTS CONNECT BY ACCOUNT_ID = PRIOR AGENCY_ID START WITH ACCOUNT_ID = 113346 ) AND                       FIELD_NAME IN (
                            SELECT FIELD_NAME FROM APPLICATION_FIELDS
                                WHERE FIELD_TYPE IN ('Checkbox','Radio','Select','SelectM', 'RadioHoriz','RadioPara') ) )
        GROUP BY FIELD_NAME, FIELD_VALUE, INSTANCE ) AD, (
            SELECT AF.FORM_ID, AF.FIELD_NAME, AF.FIELD_TEXT, AFO.OPTION_TEXT, AFO.OPTION_TYPE, AF.FIELD_ORDER, AFO.LIST_ORDER,
            DECODE(AF.FIELD_TYPE,'Checkbox',1,'SelectM',1,0) MULTIPLE_ANSWER, AF.FIELD_INSTANCE
            FROM APPLICATION_FIELDS AF, APPLICATION_FIELD_OPTIONS AFO, JOB_FORMS JF
            WHERE AFO.FIELD_NAME = AF.FIELD_NAME AND AFO.FORM_ID = AF.FORM_ID AND JF.FORM_ID = AF.FORM_ID AND AF.FIELD_TYPE IN
            ('Checkbox','Radio','Select','SelectM', 'RadioHoriz','RadioPara') AND JF.JOB_ID IN (
                SELECT JOB_ID
                FROM JOBS J
                WHERE J.ACCOUNT_ID IN (
                    SELECT ACCOUNT_ID
                    FROM AGENCY_ACCOUNTS CONNECT BY ACCOUNT_ID = PRIOR AGENCY_ID START WITH ACCOUNT_ID = 113346 ) ) ) FD
    WHERE AD.FIELD_NAME = FD.FIELD_NAME AND AD.FIELD_VALUE = FD.OPTION_TEXT AND AD.INSTANCE = FD.FIELD_INSTANCE
    GROUP BY FD.FORM_ID, FD.FIELD_NAME, FD.FIELD_TEXT, FD.OPTION_TEXT, FD.OPTION_TYPE, FD.FIELD_ORDER, FD.LIST_ORDER,
    FD.MULTIPLE_ANSWER, FD.FIELD_INSTANCE, NVL(AD.APPS,0)
    ORDER BY FD.FORM_ID ASC, FD.FIELD_ORDER ASCEXPLAIN PLAN OUTPUT
    PLAN_TABLE_OUTPUT                                                                                                                                                                                      
    Plan hash value: 3519364953                                                                                                                                                                            
    | Id  | Operation                                   | Name                       | Rows  | Bytes | Cost (%CPU)| Time     |                                                                             
    |   0 | SELECT STATEMENT                            |                            |     1 |   120 |   763   (2)| 00:00:10 |                                                                             
    |   1 |  SORT GROUP BY                              |                            |     1 |   120 |   763   (2)| 00:00:10 |                                                                             
    |   2 |   VIEW                                      |                            |     1 |   120 |   762   (1)| 00:00:10 |                                                                             
    |   3 |    HASH GROUP BY                            |                            |     1 |   220 |   762   (1)| 00:00:10 |                                                                             
    |*  4 |     FILTER                                  |                            |       |       |            |          |                                                                             
    |*  5 |      TABLE ACCESS BY INDEX ROWID            | APPLICATION_DATA           |     1 |    45 |     6   (0)| 00:00:01 |                                                                             
    PLAN_TABLE_OUTPUT                                                                                                                                                                                      
    |   6 |       NESTED LOOPS                          |                            |    40 |  8800 |   486   (2)| 00:00:06 |                                                                             
    |*  7 |        HASH JOIN                            |                            |    60 | 10500 |   125   (4)| 00:00:02 |                                                                             
    |*  8 |         HASH JOIN                           |                            |    60 |  7320 |    53   (6)| 00:00:01 |                                                                             
    |   9 |          NESTED LOOPS                       |                            |    11 |   297 |     9  (12)| 00:00:01 |                                                                             
    |  10 |           VIEW                              | VW_NSO_3                   |     3 |    15 |     5   (0)| 00:00:01 |                                                                             
    |  11 |            HASH UNIQUE                      |                            |     3 |    69 |            |          |                                                                             
    |  12 |             TABLE ACCESS BY INDEX ROWID     | JOBS                       |     3 |    30 |     3   (0)| 00:00:01 |                                                                             
    |  13 |              NESTED LOOPS                   |                            |     3 |    69 |     5   (0)| 00:00:01 |                                                                             
    |  14 |               VIEW                          | VW_NSO_1                   |     1 |    13 |     2   (0)| 00:00:01 |                                                                             
    |* 15 |                CONNECT BY WITH FILTERING    |                            |       |       |            |          |                                                                             
    |  16 |                 TABLE ACCESS BY INDEX ROWID | AGENCY_ACCOUNTS            |       |       |            |          |                                                                             
    PLAN_TABLE_OUTPUT                                                                                                                                                                                      
    |* 17 |                  INDEX UNIQUE SCAN          | AGENCY_ACCOUNTS_ACCOUNT_ID |     1 |     5 |     1   (0)| 00:00:01 |                                                                             
    |  18 |                 NESTED LOOPS                |                            |       |       |            |          |                                                                             
    |  19 |                  BUFFER SORT                |                            |       |       |            |          |                                                                             
    |  20 |                   CONNECT BY PUMP           |                            |       |       |            |          |                                                                             
    |  21 |                  TABLE ACCESS BY INDEX ROWID| AGENCY_ACCOUNTS            |     1 |    10 |     2   (0)| 00:00:01 |                                                                             
    |* 22 |                   INDEX UNIQUE SCAN         | AGENCY_ACCOUNTS_ACCOUNT_ID |     1 |       |     1   (0)| 00:00:01 |                                                                             
    |* 23 |                 TABLE ACCESS FULL           | AGENCY_ACCOUNTS            |     1 |    10 |     2   (0)| 00:00:01 |                                                                             
    |* 24 |               INDEX RANGE SCAN              | JOBS_ACCOUNT_ID            |     3 |       |     1   (0)| 00:00:01 |                                                                             
    |* 25 |           INDEX RANGE SCAN                  | JOBS_FORMS_JID_FID         |     4 |    88 |     1   (0)| 00:00:01 |                                                                             
    |* 26 |          TABLE ACCESS FULL                  | APPLICATION_FIELDS         |  3579 |   332K|    43   (3)| 00:00:01 |                                                                             
    |  27 |         TABLE ACCESS FULL                   | APPLICATION_FIELD_OPTIONS  | 32897 |  1702K|    72   (3)| 00:00:01 |                                                                             
    PLAN_TABLE_OUTPUT                                                                                                                                                                                      
    |* 28 |        INDEX RANGE SCAN                     | IDX$$_B8D40001             |     4 |       |     3   (0)| 00:00:01 |                                                                             
    |* 29 |      FILTER                                 |                            |       |       |            |          |                                                                             
    |  30 |       MERGE JOIN CARTESIAN                  |                            |     3 |   225 |    11   (0)| 00:00:01 |                                                                             
    |  31 |        NESTED LOOPS                         |                            |     1 |    53 |     6   (0)| 00:00:01 |                                                                             
    |  32 |         NESTED LOOPS                        |                            |     1 |    40 |     4   (0)| 00:00:01 |                                                                             
    |* 33 |          TABLE ACCESS BY INDEX ROWID        | APPLICATIONS               |     1 |    30 |     3   (0)| 00:00:01 |                                                                             
    |* 34 |           INDEX UNIQUE SCAN                 | APPS_APP_ID                |     1 |       |     2   (0)| 00:00:01 |                                                                             
    |  35 |          TABLE ACCESS BY INDEX ROWID        | JOBS                       | 18780 |   183K|     1   (0)| 00:00:01 |                                                                             
    |* 36 |           INDEX UNIQUE SCAN                 | JOBS_JOB_ID                |     1 |       |     0   (0)| 00:00:01 |                                                                             
    |* 37 |         VIEW                                | VW_NSO_2                   |     1 |    13 |     2   (0)| 00:00:01 |                                                                             
    |* 38 |          CONNECT BY WITH FILTERING          |                            |       |       |            |          |                                                                             
    PLAN_TABLE_OUTPUT                                                                                                                                                                                      
    |  39 |           TABLE ACCESS BY INDEX ROWID       | AGENCY_ACCOUNTS            |       |       |            |          |                                                                             
    |* 40 |            INDEX UNIQUE SCAN                | AGENCY_ACCOUNTS_ACCOUNT_ID |     1 |     5 |     1   (0)| 00:00:01 |                                                                             
    |  41 |           NESTED LOOPS                      |                            |       |       |            |          |                                                                             
    |  42 |            BUFFER SORT                      |                            |       |       |            |          |                                                                             
    |  43 |             CONNECT BY PUMP                 |                            |       |       |            |          |                                                                             
    |  44 |            TABLE ACCESS BY INDEX ROWID      | AGENCY_ACCOUNTS            |     1 |    10 |     2   (0)| 00:00:01 |                                                                             
    |* 45 |             INDEX UNIQUE SCAN               | AGENCY_ACCOUNTS_ACCOUNT_ID |     1 |       |     1   (0)| 00:00:01 |                                                                             
    |* 46 |           TABLE ACCESS FULL                 | AGENCY_ACCOUNTS            |     1 |    10 |     2   (0)| 00:00:01 |                                                                             
    |  47 |        BUFFER SORT                          |                            |     3 |    66 |     9   (0)| 00:00:01 |                                                                             
    |  48 |         INLIST ITERATOR                     |                            |       |       |            |          |                                                                             
    |* 49 |          INDEX RANGE SCAN                   | IDX$$_91CA0001             |     3 |    66 |     5   (0)| 00:00:01 |                                                                             
    PLAN_TABLE_OUTPUT                                                                                                                                                                                      
    |* 50 |       FILTER                                |                            |       |       |            |          |                                                                             
    |* 51 |        CONNECT BY WITH FILTERING            |                            |       |       |            |          |                                                                             
    |  52 |         TABLE ACCESS BY INDEX ROWID         | AGENCY_ACCOUNTS            |       |       |            |          |                                                                             
    |* 53 |          INDEX UNIQUE SCAN                  | AGENCY_ACCOUNTS_ACCOUNT_ID |     1 |     5 |     1   (0)| 00:00:01 |                                                                             
    |  54 |         NESTED LOOPS                        |                            |       |       |            |          |                                                                             
    |  55 |          BUFFER SORT                        |                            |       |       |            |          |                                                                             
    |  56 |           CONNECT BY PUMP                   |                            |       |       |            |          |                                                                             
    |  57 |          TABLE ACCESS BY INDEX ROWID        | AGENCY_ACCOUNTS            |     1 |    10 |     2   (0)| 00:00:01 |                                                                             
    |* 58 |           INDEX UNIQUE SCAN                 | AGENCY_ACCOUNTS_ACCOUNT_ID |     1 |       |     1   (0)| 00:00:01 |                                                                             
    |* 59 |         TABLE ACCESS FULL                   | AGENCY_ACCOUNTS            |     1 |    10 |     2   (0)| 00:00:01 |                                                                             
    PLAN_TABLE_OUTPUT                                                                                                                                                                                      
    Predicate Information (identified by operation id):                                                                                                                                                    
       4 - filter( EXISTS (SELECT 0 FROM "APPLICATIONS" "A","JOBS" "SYS_ALIAS_1", (SELECT "ACCOUNT_ID" "$nso_col_1"                                                                                        
                  FROM "AGENCY_ACCOUNTS" "AGENCY_ACCOUNTS" WHERE "ACCOUNT_ID"=NULL) "VW_NSO_2","APPLICATION_FIELDS"                                                                                        
                  "APPLICATION_FIELDS" WHERE  EXISTS (SELECT 0 FROM "AGENCY_ACCOUNTS" "AGENCY_ACCOUNTS" WHERE "ACCOUNT_ID"=NULL AND                                                                        
                  ("ACCOUNT_ID"=:B1)) AND ("FIELD_TYPE"='Checkbox' OR "FIELD_TYPE"='Radio' OR "FIELD_TYPE"='RadioHoriz' OR                                                                                 
                  "FIELD_TYPE"='RadioPara' OR "FIELD_TYPE"='Select' OR "FIELD_TYPE"='SelectM') AND "FIELD_NAME"=:B2 AND                                                                                    
                  "A"."ACCOUNT_ID"="$nso_col_1" AND "A"."JOB_ID"="JOB_ID" AND "A"."APPLICATION_ID"=:B3 AND                                                                                                 
                  DECODE("A"."TRAY",'Incomplete','Incomplete','Complete')='Complete' AND "A"."DELETED"=0))                                                                                                 
    PLAN_TABLE_OUTPUT                                                                                                                                                                                      
       5 - filter("FIELD_NAME"="AF"."FIELD_NAME" AND "INSTANCE"="AF"."FIELD_INSTANCE")                                                                                                                     
       7 - access("AFO"."FIELD_NAME"="AF"."FIELD_NAME" AND "AFO"."FORM_ID"="AF"."FORM_ID")                                                                                                                 
       8 - access("JF"."FORM_ID"="AF"."FORM_ID")                                                                                                                                                           
      15 - filter("ACCOUNT_ID"=113346)                                                                                                                                                                     
      17 - access("ACCOUNT_ID"=113346)                                                                                                                                                                     
      22 - access("ACCOUNT_ID"=NULL)                                                                                                                                                                       
      23 - access("ACCOUNT_ID"=NULL)                                                                                                                                                                       
      24 - access("J"."ACCOUNT_ID"="$nso_col_1")                                                                                                                                                           
      25 - access("JF"."JOB_ID"="$nso_col_1")                                                                                                                                                              
      26 - filter("AF"."FIELD_TYPE"='Checkbox' OR "AF"."FIELD_TYPE"='Radio' OR "AF"."FIELD_TYPE"='RadioHoriz' OR                                                                                           
                  "AF"."FIELD_TYPE"='RadioPara' OR "AF"."FIELD_TYPE"='Select' OR "AF"."FIELD_TYPE"='SelectM')                                                                                              
    PLAN_TABLE_OUTPUT  FOR THE QUERY                                                                                                                                                                                    
      28 - access("FIELD_VALUE"="AFO"."OPTION_TEXT")                                                                                                                                                       
      29 - filter( EXISTS (SELECT 0 FROM "AGENCY_ACCOUNTS" "AGENCY_ACCOUNTS" WHERE "ACCOUNT_ID"=NULL AND                                                                                                   
                  ("ACCOUNT_ID"=:B1)))                                                                                                                                                                     
      33 - filter(DECODE("A"."TRAY",'Incomplete','Incomplete','Complete')='Complete' AND "A"."DELETED"=0)                                                                                                  
      34 - access("A"."APPLICATION_ID"=:B1)                                                                                                                                                                
      36 - access("A"."JOB_ID"="JOB_ID")                                                                                                                                                                   
      37 - filter("A"."ACCOUNT_ID"="$nso_col_1")                                                                                                                                                           
      38 - filter("ACCOUNT_ID"=113346)                                                                                                                                                                     
      40 - access("ACCOUNT_ID"=113346)                                                                                                                                                                     
      45 - access("ACCOUNT_ID"=NULL)                                                                                                                                                                       
      46 - access("ACCOUNT_ID"=NULL)                                                                                                                                                                       
    PLAN_TABLE_OUTPUT                                                                                                                                                                                      
      49 - access("FIELD_NAME"=:B1 AND ("FIELD_TYPE"='Checkbox' OR "FIELD_TYPE"='Radio' OR "FIELD_TYPE"='RadioHoriz'                                                                                       
                  OR "FIELD_TYPE"='RadioPara' OR "FIELD_TYPE"='Select' OR "FIELD_TYPE"='SelectM'))                                                                                                         
      50 - filter("ACCOUNT_ID"=:B1)                                                                                                                                                                        
      51 - filter("ACCOUNT_ID"=:B1)                                                                                                                                                                        
      53 - access("ACCOUNT_ID"=:B1)                                                                                                                                                                        
      58 - access("ACCOUNT_ID"=NULL)                                                                                                                                                                       
      59 - access("ACCOUNT_ID"=NULL)                                                                                                                                                                       
    106 rows selected.TKPROF FOR THE QUERY
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.05       0.08          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch       17   1040.45    1018.36          0   48926569          0         229
    total       19   1040.50    1018.44          0   48926569          0         229
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 68
    Rows     Row Source Operation
        229  SORT GROUP BY (cr=48926569 pr=0 pw=0 time=1018362160 us)
        454   VIEW  (cr=48926569 pr=0 pw=0 time=1018361382 us)
        454    HASH GROUP BY (cr=48926569 pr=0 pw=0 time=1018360468 us)
    185302     FILTER  (cr=48926569 pr=0 pw=0 time=877249113 us)
    1440799      TABLE ACCESS BY INDEX ROWID APPLICATION_DATA (cr=11309333 pr=0 pw=0 time=213262026 us)
    82907114       NESTED LOOPS  (cr=174051 pr=0 pw=0 time=166906535 us)
       1790        HASH JOIN  (cr=625 pr=0 pw=0 time=41617 us)
        121         HASH JOIN  (cr=310 pr=0 pw=0 time=11263 us)
         39          NESTED LOOPS  (cr=121 pr=0 pw=0 time=6894 us)
         44           VIEW  VW_NSO_3 (cr=75 pr=0 pw=0 time=6424 us)
         44            HASH UNIQUE (cr=75 pr=0 pw=0 time=6333 us)
         44             TABLE ACCESS BY INDEX ROWID JOBS (cr=75 pr=0 pw=0 time=3090 us)
         52              NESTED LOOPS  (cr=32 pr=0 pw=0 time=58177 us)
          7               VIEW  VW_NSO_1 (cr=23 pr=0 pw=0 time=1242 us)
          7                CONNECT BY WITH FILTERING (cr=23 pr=0 pw=0 time=1212 us)
          1                 TABLE ACCESS BY INDEX ROWID AGENCY_ACCOUNTS (cr=3 pr=0 pw=0 time=185 us)
          1                  INDEX UNIQUE SCAN AGENCY_ACCOUNTS_ACCOUNT_ID (cr=2 pr=0 pw=0 time=100 us)(object id 60086)
          6                 NESTED LOOPS  (cr=20 pr=0 pw=0 time=590 us)
          7                  BUFFER SORT (cr=0 pr=0 pw=0 time=248 us)
          7                   CONNECT BY PUMP  (cr=0 pr=0 pw=0 time=95 us)
          6                  TABLE ACCESS BY INDEX ROWID AGENCY_ACCOUNTS (cr=20 pr=0 pw=0 time=314 us)
          6                   INDEX UNIQUE SCAN AGENCY_ACCOUNTS_ACCOUNT_ID (cr=14 pr=0 pw=0 time=188 us)(object id 60086)
          0                 TABLE ACCESS FULL AGENCY_ACCOUNTS (cr=0 pr=0 pw=0 time=0 us)
         44               INDEX RANGE SCAN JOBS_ACCOUNT_ID (cr=9 pr=0 pw=0 time=280 us)(object id 60253)
         39           INDEX RANGE SCAN JOBS_FORMS_JID_FID (cr=46 pr=0 pw=0 time=968 us)(object id 60299)
       3579          TABLE ACCESS FULL APPLICATION_FIELDS (cr=189 pr=0 pw=0 time=14469 us)
      32524         TABLE ACCESS FULL APPLICATION_FIELD_OPTIONS (cr=315 pr=0 pw=0 time=32629 us)
    82905323        INDEX RANGE SCAN IDX$$_B8D40001 (cr=173426 pr=0 pw=0 time=83870105 us)(object id 60121)
    185297      FILTER  (cr=37617236 pr=0 pw=0 time=749052070 us)
    185297       MERGE JOIN CARTESIAN (cr=37617196 pr=0 pw=0 time=742583363 us)
    185297        NESTED LOOPS  (cr=35393366 pr=0 pw=0 time=706772617 us)
    1139675         NESTED LOOPS  (cr=9180841 pr=0 pw=0 time=84949686 us)
    1140164          TABLE ACCESS BY INDEX ROWID APPLICATIONS (cr=5760834 pr=0 pw=0 time=46774108 us)
    1440060           INDEX UNIQUE SCAN APPS_APP_ID (cr=4320774 pr=0 pw=0 time=24380604 us)(object id 60107)
    1139675          TABLE ACCESS BY INDEX ROWID JOBS (cr=3420007 pr=0 pw=0 time=28126171 us)
    1139675           INDEX UNIQUE SCAN JOBS_JOB_ID (cr=2280328 pr=0 pw=0 time=14563524 us)(object id 60252)
    185297         VIEW  VW_NSO_2 (cr=26212525 pr=0 pw=0 time=613602445 us)
    6866175          CONNECT BY WITH FILTERING (cr=26212525 pr=0 pw=0 time=614183170 us)
    1139675           TABLE ACCESS BY INDEX ROWID AGENCY_ACCOUNTS (cr=3419025 pr=0 pw=0 time=24323520 us)
    1139675            INDEX UNIQUE SCAN AGENCY_ACCOUNTS_ACCOUNT_ID (cr=2279350 pr=0 pw=0 time=13905212 us)(object id 60086)
    6838050           NESTED LOOPS  (cr=22793500 pr=0 pw=0 time=388173853 us)
    7977725            BUFFER SORT (cr=0 pr=0 pw=0 time=178812411 us)
    7977725             CONNECT BY PUMP  (cr=0 pr=0 pw=0 time=57522094 us)
    6838050            TABLE ACCESS BY INDEX ROWID AGENCY_ACCOUNTS (cr=22793500 pr=0 pw=0 time=179425469 us)
    6838050             INDEX UNIQUE SCAN AGENCY_ACCOUNTS_ACCOUNT_ID (cr=15955450 pr=0 pw=0 time=113988543 us)(object id 60086)
          0           TABLE ACCESS FULL AGENCY_ACCOUNTS (cr=0 pr=0 pw=0 time=0 us)
    185297        BUFFER SORT (cr=2223830 pr=0 pw=0 time=24721936 us)
    1208625         INLIST ITERATOR  (cr=2223830 pr=0 pw=0 time=26470412 us)
    1208625          INDEX RANGE SCAN IDX$$_91CA0001 (cr=2223830 pr=0 pw=0 time=18174073 us)(object id 60129)
          2       FILTER  (cr=40 pr=0 pw=0 time=1292 us)
          2        CONNECT BY WITH FILTERING (cr=40 pr=0 pw=0 time=1276 us)
          2         TABLE ACCESS BY INDEX ROWID AGENCY_ACCOUNTS (cr=6 pr=0 pw=0 time=86 us)
          2          INDEX UNIQUE SCAN AGENCY_ACCOUNTS_ACCOUNT_ID (cr=4 pr=0 pw=0 time=46 us)(object id 60086)
         10         NESTED LOOPS  (cr=34 pr=0 pw=0 time=791 us)
         12          BUFFER SORT (cr=0 pr=0 pw=0 time=369 us)
         12           CONNECT BY PUMP  (cr=0 pr=0 pw=0 time=127 us)
         10          TABLE ACCESS BY INDEX ROWID AGENCY_ACCOUNTS (cr=34 pr=0 pw=0 time=376 us)
         10           INDEX UNIQUE SCAN AGENCY_ACCOUNTS_ACCOUNT_ID (cr=24 pr=0 pw=0 time=242 us)(object id 60086)
          0         TABLE ACCESS FULL AGENCY_ACCOUNTS (cr=0 pr=0 pw=0 time=0 us)Any help in tuning this query to run faster will be highly appreciated. I also noticed merge join certesian on the tkprof and explain plan. Any idea in takling that will also be appreciated.
    Cheers,
    Ade

    It's quite hard to tune a query without seeing the table structure and available indices as well as relationship between each other but I'll try.
    In your sql which you've given the table alias AD, you have this filter criteria
                  AND    FIELD_NAME IN (                        
                         SELECT FIELD_NAME
                         FROM   APPLICATION_FIELDS                            
                         WHERE  FIELD_TYPE IN ('Checkbox','Radio','Select','SelectM', 'RadioHoriz','RadioPara')
                         ) </br>
    My question is, is FIELD_NAME a column in the APPLICATION_DATA table? If it is, try moving this clause outside of the current sub-query it is in, i.e. one more level up. It looks like you put them inside the wrong level.
    I would also try converting this <COL> IN <SUB-QUERY> to a join, if that wouldn't affect the no. of rows returned. I can't tell for sure since I dont know the relationship between your tables.
    It looks to me like you're doing this
    SELECT <col list>
    FROM   ( SELECT                                         -- LEVEL 1
             FROM   APPLICATION_DATA AD
             WHERE  AD.APPLICAITON_ID IN (                  -- LEVEL 2
                    SELECT
                    FROM   APPLICATIONS A
                    WHERE  A.JOB_ID IN (
                           <SUBQUERY>
                    AND    A.ACCOUNT_ID IN (
                           <SUBQUERY>
                    AND FIELDNAME IN ( -- SHOULD BE INSIDE LEVEL1
    <SUBQUERY>
           ) AD,
           ( SELECT ....
           ) FD
    WHERE  ....

  • Help to rewrite the query --performance issue

    Hi ,
    Please help to rewrite the query since it's performance is not good.Especially second inline query(CASE statements are therein select caluse ..)is taking more cost.
    Database Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bi
    SELECT *
    FROM
      (SELECT q.*,
        COUNT(*) OVER() AS record_count,
        ROWNUM          AS row_num
      FROM
        (SELECT ExName.examiner_code,
          examiner_name,
          :v_year,
          :v_month,
          count_fb,
          NVL(count_entered_fb, 0) count_entered_fb,
          NVL(count_sent_fb, 0) count_sent_fb,
          NVL(count_edited_fb, 0) count_edited_fb,
          NVL(count_complete_fb, 0) count_complete_fb,
          NVL(count_withibcardiff_fb, 0) count_withibcardiff_fb
        FROM
          (SELECT examiner_code,
            COUNT(*) AS count_fb
          FROM
            (SELECT
                        examiner_code,
              paper_code,
              assessment_school
            FROM
              ( SELECT DISTINCT ce.examiner_code,
                ce.paper_code,
                ce.assessment_school
              FROM
                (SELECT
                  DISTINCT assessment_school,
                  paper_code,
                  examiner_code
                FROM candidate_examiner_allocation cea
                WHERE cea.element = 'Moderation of IA'
                AND cea.year      = :v_year
                AND cea.month     = :v_month
                ) ce,
                subject_group sg,
                subject_component sc
              WHERE (:v_padded_examiner_code IS NULL
              OR ce.examiner_code            = :v_padded_examiner_code)
              AND (:v_subject_group          IS NULL
              OR sg.group_number             = :v_subject_group)
              AND sg.year                    = :v_year
              AND sg.month                   = :v_month
              AND sc.year                    = :v_year
              AND sc.month                   = :v_month
              AND sc.paper_code              = ce.paper_code
              AND sc.subject                 = sg.subject
              AND sc.lvl                     = sg.lvl
              AND (:v_subject                IS NULL
              OR sc.subject                  = :v_subject)
              AND (:v_lvl                    IS NULL
              OR sc.lvl                      = :v_lvl)
              ) ea
          GROUP BY examiner_code
          ) ExName,
          (SELECT examiner_code,
            COUNT(
            CASE
              WHEN UPPER(wfi.status) = 'ENTERED'
              THEN 1
              ELSE NULL
            END) AS count_entered_fb,
            COUNT(
            CASE
              WHEN UPPER(wfi.status) = 'SENT'
              THEN 1
              ELSE NULL
            END) AS count_sent_fb,
            COUNT(
            CASE
              WHEN UPPER(wfi.status) = 'EDITED'
              THEN 1
              ELSE NULL
            END) AS count_edited_fb,
            COUNT(
            CASE
              WHEN UPPER(wfi.status) = 'COMPLETE'
              THEN 1
              ELSE NULL
            END) AS count_complete_fb,
            COUNT(
            CASE
              WHEN UPPER(wfi.status) = 'WITH IBCARDIFF'
              THEN 1
              ELSE NULL
            END) AS count_withibcardiff_fb
          FROM ia_instances ia1,
            workflow_instance wfi
          WHERE wfi.instance_id = ia1.workflow_instance_id
          AND ia1.year          = :v_year
          AND ia1.month         = :v_month
          GROUP BY ia1.year,
            ia1.month,
            examiner_code
          ) iaF,
          (SELECT person_code,
            title
            || ' '
            || firstname
            || ' '
            || lastname AS examiner_name
          FROM person
          WHERE :v_examiner_name IS NULL
          OR UPPER(title
            || ' '
            || firstname
            || ' '
            || lastname) LIKE :v_search_examiner_name
          ) P
        WHERE ExName.examiner_code = iaF.examiner_code (+)
        AND ExName.examiner_code   = p.person_code
        ORDER BY ExName.examiner_code
        ) q
      ) rc
    WHERE row_num >= :v_start_row
    AND row_num   <= (:v_start_row+(:v_max_row-1));explain plan
    line 1: SQLPLUS Command Skipped: set linesize 130
    line 2: SQLPLUS Command Skipped: set pagesize 0
    PLAN_TABLE_OUTPUT                                                                                                                                                                                                                                                                                           
    Plan hash value: 1581970599                                                                                                                                                                                                                                                                                 
    | Id  | Operation                                 | Name                           | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |                                                                                                                                                                        
    |   0 | SELECT STATEMENT                          |                                |     1 |   276 |       |  2187   (6)| 00:00:34 |                                                                                                                                                                        
    |*  1 |  FILTER                                   |                                |       |       |       |            |          |                                                                                                                                                                        
    |*  2 |   VIEW                                    |                                |     1 |   276 |       |  2187   (6)| 00:00:34 |                                                                                                                                                                        
    |   3 |    WINDOW BUFFER                          |                                |     1 |   250 |       |  2187   (6)| 00:00:34 |                                                                                                                                                                        
    |   4 |     COUNT                                 |                                |       |       |       |            |          |                                                                                                                                                                        
    |   5 |      VIEW                                 |                                |     1 |   250 |       |  2187   (6)| 00:00:34 |                                                                                                                                                                        
    |   6 |       SORT ORDER BY                       |                                |     1 |   119 |       |  2187   (6)| 00:00:34 |                                                                                                                                                                        
    |   7 |        NESTED LOOPS                       |                                |     1 |   119 |       |  2186   (6)| 00:00:34 |                                                                                                                                                                        
    |*  8 |         HASH JOIN OUTER                   |                                |     1 |    92 |       |  2185   (6)| 00:00:34 |                                                                                                                                                                        
    |   9 |          VIEW                             |                                |     1 |    20 |       |    51   (4)| 00:00:01 |                                                                                                                                                                        
    |  10 |           SORT GROUP BY                   |                                |     1 |     7 |       |    51   (4)| 00:00:01 |                                                                                                                                                                        
    |  11 |            VIEW                           |                                |     1 |     7 |       |    51   (4)| 00:00:01 |                                                                                                                                                                        
    |  12 |             SORT UNIQUE                   |                                |     1 |   127 |       |    51   (4)| 00:00:01 |                                                                                                                                                                        
    |  13 |              NESTED LOOPS                 |                                |     1 |   127 |       |    50   (2)| 00:00:01 |                                                                                                                                                                        
    |* 14 |               HASH JOIN                   |                                |     1 |    68 |       |    44   (3)| 00:00:01 |                                                                                                                                                                        
    |* 15 |                TABLE ACCESS BY INDEX ROWID| SUBJECT_COMPONENT              |    13 |   520 |       |    40   (0)| 00:00:01 |                                                                                                                                                                        
    |* 16 |                 INDEX RANGE SCAN          | SUBJECT_COMPONENT_ASSESS_TYPE  |  1059 |       |       |     9   (0)| 00:00:01 |                                                                                                                                                                        
    |* 17 |                INDEX RANGE SCAN           | SUBJECT_GROUP_PK               |    41 |  1148 |       |     3   (0)| 00:00:01 |                                                                                                                                                                        
    |* 18 |               INDEX RANGE SCAN            | CEA_AUTOMATIC_ALLOCATION_STATS |     5 |   295 |       |     6   (0)| 00:00:01 |                                                                                                                                                                        
    |  19 |          VIEW                             |                                |   679 | 48888 |       |  2133   (6)| 00:00:33 |                                                                                                                                                                        
    |  20 |           SORT GROUP BY                   |                                |   679 | 25123 |       |  2133   (6)| 00:00:33 |                                                                                                                                                                        
    |* 21 |            HASH JOIN                      |                                | 52408 |  1893K|  1744K|  2126   (6)| 00:00:33 |                                                                                                                                                                        
    |  22 |             TABLE ACCESS BY INDEX ROWID   | IA_INSTANCES                   | 52408 |  1125K|       |   688   (1)| 00:00:11 |                                                                                                                                                                        
    |* 23 |              INDEX RANGE SCAN             | IND_IA_INSTANCES               | 49077 |       |       |   137   (2)| 00:00:03 |                                                                                                                                                                        
    |  24 |             TABLE ACCESS FULL             | WORKFLOW_INSTANCE              |  1075K|    15M|       |   960   (7)| 00:00:15 |                                                                                                                                                                        
    |* 25 |         TABLE ACCESS BY INDEX ROWID       | PERSON                         |     1 |    27 |       |     1   (0)| 00:00:01 |                                                                                                                                                                        
    |* 26 |          INDEX UNIQUE SCAN                | PERSON_PK                      |     1 |       |       |     0   (0)| 00:00:01 |                                                                                                                                                                        
    Predicate Information (identified by operation id):                                                                                                                                                                                                                                                         
       1 - filter(TO_NUMBER(:V_START_ROW)<=TO_NUMBER(:V_START_ROW)+(TO_NUMBER(:V_MAX_ROW)-1))                                                                                                                                                                                                                   
       2 - filter("ROW_NUM">=TO_NUMBER(:V_START_ROW) AND "ROW_NUM"<=TO_NUMBER(:V_START_ROW)+(TO_NUMBER(:V_MAX_ROW)-1))                                                                                                                                                                                          
       8 - access("EXNAME"."EXAMINER_CODE"="IAF"."EXAMINER_CODE"(+))                                                                                                                                                                                                                                            
      14 - access("SC"."SUBJECT"="SG"."SUBJECT" AND "SC"."LVL"="SG"."LVL")                                                                                                                                                                                                                                      
      15 - filter((:V_SUBJECT IS NULL OR "SC"."SUBJECT"=:V_SUBJECT) AND ("SC"."LVL"=:V_LVL OR :V_LVL IS NULL))                                                                                                                                                                                                  
      16 - access("SC"."YEAR"=TO_NUMBER(:V_YEAR) AND "SC"."MONTH"=:V_MONTH)                                                                                                                                                                                                                                     
      17 - access("SG"."YEAR"=TO_NUMBER(:V_YEAR) AND "SG"."MONTH"=:V_MONTH)                                                                                                                                                                                                                                     
           filter(:V_SUBJECT_GROUP IS NULL OR "SG"."GROUP_NUMBER"=TO_NUMBER(:V_SUBJECT_GROUP))                                                                                                                                                                                                                  
      18 - access("CEA"."YEAR"=TO_NUMBER(:V_YEAR) AND "CEA"."MONTH"=:V_MONTH AND "SC"."PAPER_CODE"="PAPER_CODE" AND                                                                                                                                                                                             
                  "CEA"."ELEMENT"='Moderation of IA')                                                                                                                                                                                                                                                           
           filter("CEA"."ELEMENT"='Moderation of IA' AND (:V_PADDED_EXAMINER_CODE IS NULL OR                                                                                                                                                                                                                    
                  "EXAMINER_CODE"=:V_PADDED_EXAMINER_CODE))                                                                                                                                                                                                                                                     
      21 - access("WFI"."INSTANCE_ID"="IA1"."WORKFLOW_INSTANCE_ID")                                                                                                                                                                                                                                             
      23 - access("IA1"."YEAR"=TO_NUMBER(:V_YEAR) AND "IA1"."MONTH"=:V_MONTH)                                                                                                                                                                                                                                   
      25 - filter(:V_EXAMINER_NAME IS NULL OR UPPER("TITLE"||' '||"FIRSTNAME"||' '||"LASTNAME") LIKE :V_SEARCH_EXAMINER_NAME)                                                                                                                                                                                   
      26 - access("EXNAME"."EXAMINER_CODE"="PERSON_CODE")                                                                                                                                                                                                                                                       
    53 rows selected

    Hi,
    please find the below rigjt explan paln.
    PLAN_TABLE_OUTPUT                                                                                                                                                                                                                                                                                           
    SQL_ID  2ct41vyyzqyh7, child number 0                                                                                                                                                                                                                                                                       
    SELECT *  FROM    (SELECT q.*,      COUNT(*) OVER() AS record_count,      ROWNUM          AS row_num    FROM      (SELECT                                                                                                                                                                                   
    ExName.examiner_code,        examiner_name,        :v_year,        :v_month,        count_fb,        NVL(count_entered_fb,                                                                                                                                                                                  
    0) count_entered_fb,        NVL(count_sent_fb, 0) count_sent_fb,        NVL(count_edited_fb, 0) count_edited_fb,                                                                                                                                                                                            
    NVL(count_complete_fb, 0) count_complete_fb,        NVL(count_withibcardiff_fb, 0) count_withibcardiff_fb      FROM                                                                                                                                                                                         
    (SELECT examiner_code,          COUNT(*) AS count_fb        FROM          (SELECT                                                                                                                                                                                                 
           examiner_code,            paper_code,            assessment_school          FROM            ( SELECT DISTINCT                                                                                                                                                                                        
    ce.examiner_code,              ce.paper_code,              ce.assessment_school            FROM              (SELECT                                                                                                                                                                                        
                            DISTINCT assessment_school,                                                                                                                                                                                                          
    paper_code,                examiner                                                                                                                                                                                                                                                                         
    Plan hash value: 651311258                                                                                                                                                                                                                                                                                  
    | Id  | Operation                                | Name                           | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |                                                                                                                                                                         
    |   0 | SELECT STATEMENT                         |                                |       |       |       |  2785 (100)|          |                                                                                                                                                                         
    |*  1 |  FILTER                                  |                                |       |       |       |            |          |                                                                                                                                                                         
    |*  2 |   VIEW                                   |                                |     4 |  1104 |       |  2785   (7)| 00:00:43 |                                                                                                                                                                         
    |   3 |    WINDOW BUFFER                         |                                |     4 |  1000 |       |  2785   (7)| 00:00:43 |                                                                                                                                                                         
    |   4 |     COUNT                                |                                |       |       |       |            |          |                                                                                                                                                                         
    |   5 |      VIEW                                |                                |     4 |  1000 |       |  2785   (7)| 00:00:43 |                                                                                                                                                                         
    |   6 |       NESTED LOOPS                       |                                |     4 |   476 |       |  2785   (7)| 00:00:43 |                                                                                                                                                                         
    |   7 |        MERGE JOIN OUTER                  |                                |     4 |   368 |       |  2781   (7)| 00:00:43 |                                                                                                                                                                         
    |   8 |         VIEW                             |                                |     4 |    80 |       |    72   (3)| 00:00:02 |                                                                                                                                                                         
    |   9 |          SORT GROUP BY                   |                                |     4 |    28 |       |    72   (3)| 00:00:02 |                                                                                                                                                                         
    |  10 |           VIEW                           |                                |     4 |    28 |       |    72   (3)| 00:00:02 |                                                                                                                                                                         
    |  11 |            SORT UNIQUE                   |                                |     4 |   508 |       |    72   (3)| 00:00:02 |                                                                                                                                                                         
    |  12 |             NESTED LOOPS                 |                                |     4 |   508 |       |    71   (2)| 00:00:02 |                                                                                                                                                                         
    |* 13 |              HASH JOIN                   |                                |     1 |    68 |       |    44   (3)| 00:00:01 |                                                                                                                                                                         
    |* 14 |               TABLE ACCESS BY INDEX ROWID| SUBJECT_COMPONENT              |    13 |   520 |       |    40   (0)| 00:00:01 |                                                                                                                                                                         
    |* 15 |                INDEX RANGE SCAN          | SUBJECT_COMPONENT_ASSESS_TYPE  |  1059 |       |       |     9   (0)| 00:00:01 |                                                                                                                                                                         
    |* 16 |               INDEX RANGE SCAN           | SUBJECT_GROUP_PK               |    41 |  1148 |       |     3   (0)| 00:00:01 |                                                                                                                                                                         
    |* 17 |              INDEX RANGE SCAN            | CEA_AUTOMATIC_ALLOCATION_STATS |    30 |  1770 |       |    27   (0)| 00:00:01 |                                                                                                                                                                         
    |* 18 |         SORT JOIN                        |                                |   576 | 41472 |       |  2709   (7)| 00:00:42 |                                                                                                                                                                         
    |  19 |          VIEW                            |                                |   576 | 41472 |       |  2708   (7)| 00:00:42 |                                                                                                                                                                         
    |  20 |           SORT GROUP BY                  |                                |   576 | 21312 |       |  2708   (7)| 00:00:42 |                                                                                                                                                                         
    |* 21 |            HASH JOIN                     |                                | 52408 |  1893K|  1744K|  2701   (7)| 00:00:41 |                                                                                                                                                                         
    |* 22 |             TABLE ACCESS FULL            | IA_INSTANCES                   | 52408 |  1125K|       |  1263   (6)| 00:00:20 |                                                                                                                                                                         
    |  23 |             TABLE ACCESS FULL            | WORKFLOW_INSTANCE              |  1075K|    15M|       |   960   (7)| 00:00:15 |                                                                                                                                                                         
    |* 24 |        TABLE ACCESS BY INDEX ROWID       | PERSON                         |     1 |    27 |       |     1   (0)| 00:00:01 |                                                                                                                                                                         
    |* 25 |         INDEX UNIQUE SCAN                | PERSON_PK                      |     1 |       |       |     0   (0)|          |                                                                                                                                                                         
    Predicate Information (identified by operation id):                                                                                                                                                                                                                                                         
       1 - filter(TO_NUMBER(:V_START_ROW)<=TO_NUMBER(:V_START_ROW)+(TO_NUMBER(:V_MAX_ROW)-1))                                                                                                                                                                                                                   
       2 - filter(("ROW_NUM">=TO_NUMBER(:V_START_ROW) AND "ROW_NUM"<=TO_NUMBER(:V_START_ROW)+(TO_NUMBER(:V_MAX_ROW)-1)))                                                                                                                                                                                        
      13 - access("SC"."SUBJECT"="SG"."SUBJECT" AND "SC"."LVL"="SG"."LVL")                                                                                                                                                                                                                                      
      14 - filter(((:V_SUBJECT IS NULL OR "SC"."SUBJECT"=:V_SUBJECT) AND ("SC"."LVL"=:V_LVL OR :V_LVL IS NULL)))                                                                                                                                                                                                
      15 - access("SC"."YEAR"=TO_NUMBER(:V_YEAR) AND "SC"."MONTH"=:V_MONTH)                                                                                                                                                                                                                                     
      16 - access("SG"."YEAR"=TO_NUMBER(:V_YEAR) AND "SG"."MONTH"=:V_MONTH)                                                                                                                                                                                                                                     
           filter((:V_SUBJECT_GROUP IS NULL OR "SG"."GROUP_NUMBER"=TO_NUMBER(:V_SUBJECT_GROUP)))                                                                                                                                                                                                                
      17 - access("CEA"."YEAR"=TO_NUMBER(:V_YEAR) AND "CEA"."MONTH"=:V_MONTH AND "SC"."PAPER_CODE"="PAPER_CODE" AND                                                                                                                                                                                             
                  "CEA"."ELEMENT"='Moderation of IA')                                                                                                                                                                                                                                                           
           filter(("CEA"."ELEMENT"='Moderation of IA' AND (:V_PADDED_EXAMINER_CODE IS NULL OR                                                                                                                                                                                                                   
                  "EXAMINER_CODE"=:V_PADDED_EXAMINER_CODE)))                                                                                                                                                                                                                                                    
      18 - access("EXNAME"."EXAMINER_CODE"="IAF"."EXAMINER_CODE")                                                                                                                                                                                                                                               
           filter("EXNAME"."EXAMINER_CODE"="IAF"."EXAMINER_CODE")                                                                                                                                                                                                                                               
      21 - access("WFI"."INSTANCE_ID"="IA1"."WORKFLOW_INSTANCE_ID")                                                                                                                                                                                                                                             
      22 - filter(("IA1"."MONTH"=:V_MONTH AND "IA1"."YEAR"=TO_NUMBER(:V_YEAR)))                                                                                                                                                                                                                                 
      24 - filter((:V_EXAMINER_NAME IS NULL OR UPPER("TITLE"||' '||"FIRSTNAME"||' '||"LASTNAME") LIKE :V_SEARCH_EXAMINER_NAME))                                                                                                                                                                                 
      25 - access("EXNAME"."EXAMINER_CODE"="PERSON_CODE")                                                                                                                                                                                                                                                       
    66 rows selected

  • HT202159 I am unable to download and always asking password after entering the password  also asking same question please help  me to sort out  this problem.

    I am unable to download and always asking the password it's ok for the once and it's asking more and no results only repeating the same so I am unable to download please help me to sort out this problem and my request please sort out from your side  or let me guide .

    Thanks Eric for responding.
    I checked and it does not appear in the Applications folder.
    I tried yesterday on an ethernet connection with a download speed of 2 Mbps but, unfortunately the connection died(It happened from the ISP end, which is out of my control) in between after which there was no trace of the download that happened for so long(till the internet connection death). 
    One more serious query which I am unable to understand. If the internet connection, dies in the midst of the download is in progress why is it so that the state does not persist and one has to restart the entire process again. Is there no solution for this?
    I tried so many times and its the same case after some amount of download it vanishes. So many unsuccessful attempts. I am ****** off now. Is it not possible to see Mavericks? Why does different machines of Apple behave differently? Somewhere it goes smoothly and somewhere like my mine. Why did not Apple release a non apple store version? Is this not a bad sign of letting the users struggle when something is being offered for free?
    The reason I asked as whether we can download the .app of Mavericks is that, there are so many applications that I have downloaded web and have installed. All that works fine. Can't we do the same here? You download a copy of Mavericks installer application and upload it for me in Google drive or like online storage places which can be downloaded and used by me? Help me understand.
    Thanks again.

  • Help needed for writing query

    help needed for writing query
    i have the following tables(with data) as mentioned below
    FK*-foregin key (SUBJECTS)
    FK**-foregin key (COMBINATION)
    1)SUBJECTS(table name)     
    SUB_ID(NUMBER) SUB_CODE(VARCHAR2) SUB_NAME (VARCHAR2)
    2           02           Computer Science
    3           03           Physics
    4           04           Chemistry
    5           05           Mathematics
    7           07           Commerce
    8           08           Computer Applications
    9           09           Biology
    2)COMBINATION
    COMB_ID(NUMBER) COMB_NAME(VARCHAR2) SUB_ID1(NUMBER(FK*)) SUB_ID2(NUMBER(FK*)) SUB_ID3(NUMBER(FK*)) SUBJ_ID4(NUMBER(FK*))
    383           S1      9           4           2           3
    384           S2      4           2           5           3
    ---------I actually designed the ABOVE table also like this
    3) a)COMBINATION
    COMB_ID(NUMBER) COMB_NAME(VARCHAR2)
    383           S1
    384           S2
    b)COMBINATION_DET
    COMBDET_ID(NUMBER) COMB_ID(FK**) SUB_ID(FK*)
    1               383          9
    2               383          4
    3               383          2
    4               383          3
    5               384          4
    6               384          2          
    7               384          5
    8               384          3
    Business rule: a combination consists of a maximum of 4 subjects (must contain)
    and the user is less relevant to a COMB_NAME(name of combinations) but user need
    the subjects contained in combinations
    i need the following output
    COMB_ID COMB_NAME SUBJECT1 SUBJECT2      SUBJECT3      SUBJECT4
    383     S1     Biology Chemistry      Computer Science Physics
    384     S2     Chemistry Computer Science Mathematics Physics
    or even this is enough(what i actually needed)
    COMB_ID     subjects
    383           Biology,Chemistry,Computer Science,Physics
    384           Chemistry,Computer Science,Mathematics,Physics
    you can use any of the COMBINATION table(either (2) or (3))
    and i want to know
    1)which design is good in this case
    (i think SUB_ID1,SUB_ID2,SUB_ID3,SUB_ID4 is not a
    good method to link with same table but if 4 subjects only(and must) comes
    detail table is not neccessary )
    now i am achieving the result by program-coding in C# after getting the rows from oracle
    i am using oracle 9i (also ODP.NET)
    i want to know how can i get the result in the stored procedure itsef.
    2)how it could be designed in any other way.
    any help/suggestion is welcome
    thanks for your time --Pradeesh

    Well I forgot the table-alias, here now with:
    SELECT C.COMB_ID
    , C.COMB_NAME
    , (SELECT SUB_NAME
    FROM SUBJECTS
    WHERE SUB_ID = C.SUB_ID1) AS SUBJECT_NAME1
    , (SELECT SUB_NAME
    FROM SUBJECTS
    WHERE SUB_ID = C.SUB_ID2) AS SUBJECT_NAME2
    , (SELECT SUB_NAME
    FROM SUBJECTS
    WHERE SUB_ID = C.SUB_ID3) AS SUBJECT_NAME3
    , (SELECT SUB_NAME
    FROM SUBJECTS
    WHERE SUB_ID = C.SUB_ID4) AS SUBJECT_NAME4
    FROM COMBINATION C;
    As you need exactly 4 subjects, the columns-solution is just fine I would say.

  • HELP TO TUNE THIS QUERY

    Hi,
    I'm using below query in procedure.It's taking more more time can some one help to tune this query or advice to rewrite the query.
    Databse :10.1
    SELECT   'Reading Comprehension' TEST_NAME,T.TEST_END_DATE TEST_SESSION_DATE,
            C.POOL_VERSION_ID, I.CREATED_ON POOL_CREATED_DT,
            C.ITEM_ID, C.ITEM_RESPONSE_ID, S.STUDENT_ID_PK, C.RESPONSE_KEY, C.IS_CORRECT RESPONSE_IS_CORRECT,
            T.SCORE SCALE_SCORE, C.RESPONSE_DURATION, P.ITEM_KEY,
            T.TEST_SESSION_DETAIL_ID, SYSDATE CREATED_ON
           -- BULK COLLECT INTO TV_PSYCHO_DET
            FROM
            CAT_ITEM_PARAMETER P, CAT_ITEM_USER_RESPONSE C, TEST_SESSION_DETAIL T,
            TEST_SESSION S, ITEM_POOL_VERSION I, TEST_DETAIL D
            ,INSTITUTION E
            WHERE  TRUNC(T.TEST_END_DATE) BETWEEN TO_DATE('01-11-09','dd-mm-yy') AND TO_DATE('30-11-09','dd-mm-yy')
            AND D.TEST_NAME =  'Reading Comprehension'
            AND T.TEST_SESSION_STATUS_ID = 3
            AND I.POOL_AVAILABILITY='Y'
            AND P.PRETEST=0 AND C.RESTART_FLAG=0
            AND T.TEST_DETAIL_ID = D.TEST_DETAIL_ID
            AND S.TEST_SESSION_ID = T.TEST_SESSION_ID
            AND C.TEST_SESSION_DETAIL_ID = T.TEST_SESSION_DETAIL_ID
            AND S.INSTITUTION_ID=E.INSTITUTION_ID
            AND SUBSTR(E.INSTITUTION_ID_DISPLAY,8,3) <> '000'
            AND I.ITEM_ID = C.ITEM_ID
            AND P.ITEM_ID = I.ITEM_ID;expln plan
    Plan hash value: 3712814491                                                                                                      
    | Id  | Operation                                 | Name                        | Rows  | Bytes | Cost (%CPU)| Time     | Pstart|
    Pstop |                                                                                                                          
    |   0 | SELECT STATEMENT                          |                             | 50857 |  7151K| 93382   (1)| 00:18:41 |       |
          |                                                                                                                          
    |*  1 |  FILTER                                   |                             |       |       |            |          |       |
          |                                                                                                                          
    |*  2 |   HASH JOIN                               |                             | 50857 |  7151K| 93382   (1)| 00:18:41 |       |
          |                                                                                                                          
    |   3 |    PARTITION HASH ALL                     |                             |  2312 | 23120 |    25   (0)| 00:00:01 |     1 |
        5 |                                                                                                                          
    |*  4 |     TABLE ACCESS FULL                     | CAT_ITEM_PARAMETER          |  2312 | 23120 |    25   (0)| 00:00:01 |     1 |
        5 |                                                                                                                          
    |*  5 |    HASH JOIN                              |                             | 94938 |    12M| 93356   (1)| 00:18:41 |       |
          |                                                                                                                          
    |*  6 |     TABLE ACCESS FULL                     | ITEM_POOL_VERSION           |  9036 |   132K|    30   (0)| 00:00:01 |       |
          |                                                                                                                          
    |*  7 |     TABLE ACCESS BY GLOBAL INDEX ROWID    | CAT_ITEM_USER_RESPONSE      |     9 |   279 |    18   (0)| 00:00:01 | ROWID |
    ROWID |                                                                                                                          
    |   8 |      NESTED LOOPS                         |                             | 45349 |  5270K| 93325   (1)| 00:18:40 |       |
          |                                                                                                                          
    |*  9 |       HASH JOIN                           |                             |  4923 |   423K| 11377   (1)| 00:02:17 |       |
          |                                                                                                                          
    |* 10 |        INDEX FAST FULL SCAN               | INSTI_ID_NAME_COUN_DISP_IDX |  8165 |   111K|    18   (0)| 00:00:01 |       |
          |                                                                                                                          
    |* 11 |        HASH JOIN                          |                             |  4923 |   355K| 11359   (1)| 00:02:17 |       |
          |                                                                                                                          
    |* 12 |         TABLE ACCESS BY GLOBAL INDEX ROWID| TEST_SESSION_DETAIL         |  4107 |   148K|  6804   (1)| 00:01:22 | ROWID |
    ROWID |                                                                                                                          
    |  13 |          NESTED LOOPS                     |                             |  4923 |   278K|  6806   (1)| 00:01:22 |       |
          |                                                                                                                          
    |* 14 |           INDEX RANGE SCAN                | TEST_DETAIL_AK_1            |     1 |    21 |     2   (0)| 00:00:01 |       |
          |                                                                                                                          
    |* 15 |           INDEX RANGE SCAN                | TEST_SESSION_DETAIL_FK2_I   | 39737 |       |   102   (0)| 00:00:02 |       |
          |                                                                                                                          
    |  16 |         PARTITION HASH ALL                |                             |  1672K|    25M|  4546   (1)| 00:00:55 |     1 |
        5 |                                                                                                                          
    |  17 |          TABLE ACCESS FULL                | TEST_SESSION                |  1672K|    25M|  4546   (1)| 00:00:55 |     1 |
        5 |                                                                                                                          
    |* 18 |       INDEX RANGE SCAN                    | CAT_ITEM_USER_RESP_IDX1     |    18 |       |     3   (0)| 00:00:01 |       |
          |                                                                                                                          
    Predicate Information (identified by operation id):                                                                              
       1 - filter(TO_DATE('01-11-09','dd-mm-yy')<=TO_DATE('30-11-09','dd-mm-yy'))                                                    
       2 - access("P"."ITEM_ID"="I"."ITEM_ID")                                                                                       
       4 - filter("P"."PRETEST"=0)                                                                                                   
       5 - access("I"."ITEM_ID"="C"."ITEM_ID")                                                                                       
       6 - filter("I"."POOL_AVAILABILITY"='Y')                                                                                       
       7 - filter(TO_NUMBER("C"."RESTART_FLAG")=0)                                                                                   
       9 - access("S"."INSTITUTION_ID"="E"."INSTITUTION_ID")                                                                         
      10 - filter(SUBSTR("E"."INSTITUTION_ID_DISPLAY",8,3)<>'000')                                                                   
      11 - access("S"."TEST_SESSION_ID"="T"."TEST_SESSION_ID")                                                                       
      12 - filter(TRUNC(INTERNAL_FUNCTION("T"."TEST_END_DATE"))>=TO_DATE('01-11-09','dd-mm-yy') AND "T"."TEST_SESSION_STATUS_ID"=3   
                  AND TRUNC(INTERNAL_FUNCTION("T"."TEST_END_DATE"))<=TO_DATE('30-11-09','dd-mm-yy'))                                 
      14 - access("D"."TEST_NAME"='Reading Comprehension')                                                                           
      15 - access("T"."TEST_DETAIL_ID"="D"."TEST_DETAIL_ID")                                                                         
      18 - access("C"."TEST_SESSION_DETAIL_ID"="T"."TEST_SESSION_DETAIL_ID")                                                         
    43 rows selected.Edited by: user575115 on Dec 18, 2009 12:31 AM

    When you see something like ...
       7 - filter(TO_NUMBER("C"."RESTART_FLAG")=0)                                                                                    It means that Oracle had to do a conversion for you since you aren't using the proper data type in your query.
    That would mean IF there is an index on that column, it won't be useable...

  • Need help in the sql query

    i have a table
    source table :
    create table order(name_a varchar2(100),intid number);
    insert into order values('a',1);
    insert into order values('b',1);
    insert into order values('c',1);
    insert into order values('d',1);
    insert into order values('e',2);
    insert into order values('f',2);
    insert into order values('g',2);
    i need a query , which result in the below output :
    if i look for intid=1 the query should give a,b,c,d
    if i look for intid=2 the query should give f,g
    Thanks

    Hi,
    781649 wrote:
    i have a table
    source table :
    create table order(name_a varchar2(100),intid number);
    insert into order values('a',1);
    insert into order values('b',1);
    insert into order values('c',1);
    insert into order values('d',1);
    insert into order values('e',2);
    insert into order values('f',2);
    insert into order values('g',2);Thanks for posting the CREATE TABLE and INSERT statements; it's very helpful.
    i need a query , which result in the below output :
    if i look for intid=1 the query should give a,b,c,d
    if i look for intid=2 the query should give f,gDid you mean <b>e</b>,f,g ?
    That's called String Aggregation , and how to do it depends on your version of Oracle, and your exact requirements.
    See thie following page for several techniques:
    http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php
    If you're using Oracle 10 (or higher), and it's important that the name_a's be in order in the output, then you can do this:
    WITH     got_r_num     AS
         SELECT     name_a
         ,     intid
         ,     ROW_NUMBER () OVER ( PARTITION BY  intid
                                   ORDER BY          name_a
                           )         AS r_num
         FROM     order_table                    -- ORDER is not a good table name
         WHERE     intid     IN (1)                    -- Optional
    SELECT     intid
    ,     SUBSTR ( SYS_CONNECT_BY_PATH (name_a, ',')
                , 2
                )     AS name_a_list
    FROM     got_r_num
    WHERE     CONNECT_BY_ISLEAF     = 1
    START WITH     r_num     = 1
    CONNECT BY     r_num     = PRIOR r_num + 1
         AND     intid     = PRIOR intid
    ;Starting in Oracle 11.2, LISTAGG is better.
    This does not assume that you are getting the output only for a single intid at a time. You can get any number of them in a suingle query. Of course, that number can be 1 if that's what you want.
    Edited by: Frank Kulash on Mar 24, 2011 12:19 PM

  • Need help in writing the query

    The initial data is as follows:
    ID PARENT_ID
    =============
    1 NULL
    2 NULL
    3 2
    4 6
    5 3
    6 7
    7 4
    8 NULL
    but output is as follows in such way that Parent_Id should be displayed in ID place
    ID PARENT_ID
    =============
    1 NULL
    2 NULL
    3 2
    8 NULL
    6 8
    4 6
    5 3
    7 4
    Can any one help how resolve this query?
    Thanks in advance

    Your output is inconsistent with initial data :) But
    select * from t start with parent_id is null connect by parent_id = prior id;

  • Need help in the following query

    Hi ,
    I have the following query to pull out data for a particular timeperiod( campaign)
    select
    da.acct_nr,smas.mrkt_id,smas.fld_sls_cmpgn_perd_id,smas.acct_key,smas.upln_acct_key,smas.awrd_sls_amt,smas.fld_net_sls_amt
    ,smas.stf_ind,da1.acct_nr,
    smas.fld_sls_cmpgn_perd_id,smas.acct_key,smas.upln_acct_key,smas.awrd_sls_amt,smas.fld_net_sls_amt
    ,smas.stf_ind,da1.acct_nr,prev.*
    From cdw.sum_mrkt_acct_sls smas
    join codi.dim_acct da
    on (smas.mrkt_id = da.mrkt_id and smas.acct_key = da.acct_key)
    join codi.dim_acct da1
    on (smas.mrkt_id = da1.mrkt_id and smas.UPLN_acct_key = da1.ACCT_KEY)
    where smas.acct_key in
    select dwnln_acct_key from codi.dim_ldrshp_genlgy
    where mrkt_id = 66 and fld_sls_cmpgn_perd_id = 20100304
    and root_upln_acct_key = (select acct_key from codi.dim_acct where acct_nr = '0032622' and mrkt_id = 66)
    and
    smas.mrkt_id = 66
    and smas.fld_sls_cmpgn_perd_id = 20100304
    and smas.sls_org_key <> -100
    order by 1
    So this query will pull out data for campaign 20100304
    No i want to modify the query to pull out data for 3 such campaigns.
    for a smas.acct_key
    so data will
    smas.acct_key all the data for 1st campaign , all the data for 2nd campaign. all the data for 3rd campaign
    Could you please help in modifying this query.
    Thanks

    How about this ??
    select da.acct_nr,
           smas.mrkt_id,
           smas.fld_sls_cmpgn_perd_id,
           smas.acct_key,
           smas.upln_acct_key,
           smas.awrd_sls_amt,
           smas.fld_net_sls_amt,
           smas.stf_ind,
           da1.acct_nr,
           smas.fld_sls_cmpgn_perd_id,
           smas.acct_key,
           smas.upln_acct_key,
           smas.awrd_sls_amt,
           smas.fld_net_sls_amt,
           smas.stf_ind,
           da1.acct_nr,
           prev.*
      From cdw.sum_mrkt_acct_sls smas
      join codi.dim_acct da on (smas.mrkt_id = da.mrkt_id and
                               smas.acct_key = da.acct_key)
      join codi.dim_acct da1 on (smas.mrkt_id = da1.mrkt_id and
                                smas.UPLN_acct_key = da1.ACCT_KEY)
    where smas.acct_key in (select dwnln_acct_key
                               from codi.dim_ldrshp_genlgy
                              where mrkt_id = 66
                                and fld_sls_cmpgn_perd_id in( 20100304,20100305,20100306)
                                and root_upln_acct_key =
                                    (select acct_key
                                       from codi.dim_acct
                                      where acct_nr = '0032622'
                                        and mrkt_id = 66))
       and smas.mrkt_id = 66
       and smas.fld_sls_cmpgn_perd_id in( 20100304,20100305,20100306)
       and smas.sls_org_key - 100
    order by 1

  • Need help in insert statment query

    Hi,
    I have a table T1 with values like
    col1
    1
    2
    3
    4
    I need to write insert statment for t2 as
    insert into t2(col1,col2) values ('AA',select col1 from t1);
    The output of T2 should be
    col1 col2
    AA 1
    AA 2
    AA 3
    AA 4
    Any help in modifying the query.
    Ashish

    What is wrong with this?
    INSERT INTO id_own_dw.id_t_dw_org_dq_tgt
           (cost_center_cod_vc_old,
            cost_center_cod_vc_new
         SELECT '3016052',<<<_-- this you can replace with your varibale in pl/sql block
                cost_center_cod_vc
           FROM id_own_dw.id_t_dw_msl_org_cctr2mkdiv
          WHERE busi_unit_cod_vc = '3016496'

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

  • Need help in tunnig the query

    Experts,
    Plz help in tuning this query
    SELECT
    DECODE(WSH_DELIVERY_DETAILS.LOT_NUMBER,'5I27164/1U',1, TO_NUMBER(SUBSTR(WSH_DELIVERY_DETAILS.LOT_NUMBER, (LENGTH(WSH_DELIVERY_DETAILS.LOT_NUMBER) - INSTR(REVERSE(WSH_DELIVERY_DETAILS.LOT_NUMBER),'/') + 2), (INSTR(REVERSE(WSH_DELIVERY_DETAILS.LOT_NUMBER),'/')-1))) ) AS NO_OF_PLATES,
         P_FORM.DESCRIPTION FORMOFPRODUCT,
    HZ_PARTIES.PARTY_NAME CUSTOMER, HZ_CUST_ACCOUNTS.ACCOUNT_NUMBER ACCT_NUM,
         NVL(OE_ORDER_HEADERS_ALL.CUST_PO_NUMBER,'XXXX') CUST_PO,
         INITCAP(HZ_PARTIES.ADDRESS1) BILL_ADD1,
    INITCAP(HZ_PARTIES.ADDRESS2) BILL_ADD2,
    INITCAP(HZ_PARTIES.ADDRESS3) BILL_ADD3,
    INITCAP(HZ_PARTIES.ADDRESS4) BILL_ADD4,
         INITCAP(HZ_PARTIES.CITY) BILL_CITY,
    INITCAP(HZ_PARTIES.STATE) BILL_STATE,
    HZ_PARTIES.POSTAL_CODE BILL_PC,
         INITCAP(HZ_LOCATIONS.ADDRESS1) SHIP_ADD1,
    INITCAP(HZ_LOCATIONS.ADDRESS2) SHIP_ADD2,
    INITCAP(HZ_LOCATIONS.ADDRESS3) SHIP_ADD3,
    INITCAP(HZ_LOCATIONS.ADDRESS4) SHIP_ADD4,
         INITCAP(HZ_LOCATIONS.CITY) SHIP_CITY,
    INITCAP(HZ_LOCATIONS.STATE) SHIP_STATE,
    HZ_LOCATIONS.POSTAL_CODE SHIP_PC,
         OE_TRANSACTION_TYPES_TL.NAME CATEGORY ,
         OE_ORDER_HEADERS_ALL.ORDER_NUMBER,
    OE_ORDER_HEADERS_ALL.SOURCE_DOCUMENT_ID,
    OE_ORDER_HEADERS_ALL.HEADER_ID,
    OE_ORDER_HEADERS_ALL.FREIGHT_TERMS_CODE,
    /* to_char(oe_order_headers_all.ORDERED_DATE,'DD-MON-RR HH24:MI:SS') ORDER_DATE,*/
    to_char(sysdate,'DD/MM/RRRR HH24:MI:SS') ORDERED_DATE,
         ROWNUM,
    OE_ORDER_LINES_ALL.INVENTORY_ITEM_ID,
         OE_ORDER_LINES_ALL.ORDERED_ITEM,
         OE_ORDER_LINES_ALL.ORDERED_QUANTITY,
         WSH_DELIVERY_DETAILS.SHIPPED_QUANTITY+DECODE(WSH_DELIVERY_DETAILS.DELIVERY_DETAIL_ID,129881,.22,0) AS SHIPPED_QUANTITY1, (WSH_DELIVERY_DETAILS.SHIPPED_QUANTITY+DECODE(WSH_DELIVERY_DETAILS.DELIVERY_DETAIL_ID,129881,.22,0))*OE_ORDER_LINES_ALL.UNIT_SELLING_PRICE AS LINE_PRICE,
         OE_ORDER_LINES_ALL.UNIT_SELLING_PRICE,
         JA_IN_RG_I.FOR_HOME_USE_PAY_ED_VAL,
    ----      SUBSTR(JA_IN_RG_I.EXCISE_INVOICE_NUMBER,1,2)|| SUBSTR(JA_IN_RG_I.EXCISE_INVOICE_NUMBER,4,8) INVOICE_NO,
         JA_IN_RG_I.EXCISE_INVOICE_NUMBER INVOICE_NO,
    to_char(JA_IN_RG_I.CREATION_DATE,'DD/MM/RRRR') INVOICE_DATE1,
         to_char(JA_IN_RG_I.EXCISE_INVOICE_DATE,'DD-MON-RR HH24:MI:SS') INV_DATE,
         to_char(JA_IN_RG_I.CREATION_DATE,'DD/MM/RRRR HH24:MI:SS') INVOICE_DATE,
         JA_IN_RG_I.EXCISE_DUTY_RATE,
         JA_IN_RG_I.EXCISE_DUTY_AMOUNT,
         WSH_DELIVERY_DETAILS.LOT_NUMBER,
    WSH_TRIPS.CARRIER_ID CARRIER_ID,
    WSH_TRIPS.VEHICLE_NUM_PREFIX,
    WSH_TRIPS.SEAL_CODE,
    WSH_TRIPS.ROUTING_INSTRUCTIONS,
    WSH_TRIPS.OPERATOR, WSH_NEW_DELIVERIES. DELIVERY_ID,
    WSH_NEW_DELIVERIES. ADDITIONAL_SHIPMENT_INFO TRUCK_NO,
         WSH_TRIPS.MODE_OF_TRANSPORT VEHICLE_TYPE,
    WSH_TRIPS.ATTRIBUTE6||' '|| WSH_TRIPS.ATTRIBUTE7||' '|| WSH_TRIPS.ATTRIBUTE8 REMARKS,
         WSH_TRIPS.ATTRIBUTE1 LR_NO, WSH_TRIPS.ATTRIBUTE7,
         WSH_TRIPS.ATTRIBUTE2 LR_DATE,
         DECODE(WSH_TRIPS.ATTRIBUTE3, '', '', 'ARE NO '||WSH_TRIPS.ATTRIBUTE3) AS ARE_NO,
         DECODE(WSH_TRIPS.ATTRIBUTE6, '', '', WSH_TRIPS.ATTRIBUTE6) AS REMARK1,
         DECODE(WSH_TRIPS.ATTRIBUTE4, '', '', 'R.P. NO. ' ||WSH_TRIPS.ATTRIBUTE4) AS PERMIT,
         DECODE(WSH_TRIPS.ATTRIBUTE5, '', '', 'Export Under '||WSH_TRIPS.ATTRIBUTE5) AS EXPORT_UNDER,
         DECODE(WSH_NEW_DELIVERIES.PORT_OF_DISCHARGE,'','', 'Seal No : '||WSH_NEW_DELIVERIES.PORT_OF_DISCHARGE) AS SEAL_NO,
         DECODE(WSH_NEW_DELIVERIES.DESCRIPTION, '', '', 'Container No : ' ||WSH_NEW_DELIVERIES.DESCRIPTION) AS CONTAINER_NO,
         MTL_SYSTEM_ITEMS_B.ATTRIBUTE4 AS EXCISE_TARIFF_NO,
         --MTL_SYSTEM_ITEMS_B.DESCRIPTION,
         HZ_CUST_ACCOUNTS.ACCOUNT_NUMBER,
         JSW_LOT_PACKSLIP.PACKSLIP_NO PACKSLIP,
         PR_TYPE.DESCRIPTION ||' ,'||
         P_FORM.DESCRIPTION || ' ,'||
         PR_GRADE.DESCRIPTION ||' ,'||
         PR_QTY.DESCRIPTION || ' ,'||
         DECODE(SUBSTR(PR_STL.DESCRIPTION,1,3),'Not','', PR_STL.DESCRIPTION) DESCRIPTION ,
    HZ_CUST_ACCT_SITES_ALL.ATTRIBUTE7 S_CST_NO,
    HZ_CUST_ACCT_SITES_ALL.ATTRIBUTE6 S_LST_NO,
    HZ_CUST_ACCT_SITES_ALL.ATTRIBUTE5 S_ECC_NO,
    A.ATTRIBUTE7 B_CST_NO,
    A.ATTRIBUTE6 B_LST_NO,
    INTERFACECRM.JSW_MES_COMMON_TNGL_T.JSW_ADDMINUTES(WSH_TRIPS.VEHICLE_NUM_PREFIX) POSTFIX_NUM
    FROM -- jsw_vat_slno,
         MTL_PARAMETERS,
         HZ_PARTIES,
         HZ_CUST_ACCOUNTS,
         HZ_LOCATIONS,
         HZ_PARTY_SITES,
         HZ_CUST_ACCT_SITES_ALL,
         HZ_CUST_SITE_USES_ALL,
    HZ_CUST_ACCT_SITES_ALL A,
    HZ_CUST_SITE_USES_ALL B,
         OE_TRANSACTION_TYPES_TL,
         JA_IN_RG_I,
         WSH_DELIVERY_DETAILS,
         OE_ORDER_LINES_ALL,
         OE_ORDER_HEADERS_ALL,
         WSH_DELIVERY_ASSIGNMENTS,
         WSH_NEW_DELIVERIES,
         WSH_DELIVERY_LEGS,
         WSH_TRIP_STOPS,
         WSH_TRIPS,
         MTL_SYSTEM_ITEMS_B,
         JSW_LOT_PACKSLIP,
         IC_TRAN_PND,
                   JSW_ITM_SEARCH_PRD_TYP          PR_TYPE,
              JSW_ITM_SEARCH_PRD_FRM          P_FORM     ,
                   JSW_ITM_SEARCH_PRD_GRD          PR_GRADE,      
              JSW_ITM_SEARCH_QUALITY_LEVEL PR_QTY,      
                   JSW_ITEM_SEARCH_SLITTING      PR_STL
    WHERE /* jsw_vat_slno.excise_invoice_number=ja_in_rg_i.excise_invoice_number and jsw_vat_slno.organization_id = ja_in_rg_i.organization_id */
    HZ_PARTIES.PARTY_ID = HZ_CUST_ACCOUNTS.PARTY_ID
         AND HZ_CUST_ACCOUNTS.CUST_ACCOUNT_ID = OE_ORDER_HEADERS_ALL.SOLD_TO_ORG_ID
         AND OE_ORDER_HEADERS_ALL.SHIP_TO_ORG_ID = HZ_CUST_SITE_USES_ALL.SITE_USE_ID
         AND HZ_CUST_SITE_USES_ALL.CUST_ACCT_SITE_ID = HZ_CUST_ACCT_SITES_ALL.CUST_ACCT_SITE_ID
    AND OE_ORDER_HEADERS_ALL.INVOICE_TO_ORG_ID = B.SITE_USE_ID
         AND B.CUST_ACCT_SITE_ID                          = A.CUST_ACCT_SITE_ID
         AND HZ_CUST_ACCT_SITES_ALL.PARTY_SITE_ID      = HZ_PARTY_SITES.PARTY_SITE_ID
         AND HZ_PARTY_SITES.LOCATION_ID = HZ_LOCATIONS.LOCATION_ID
         AND OE_ORDER_LINES_ALL.SHIP_FROM_ORG_ID = MTL_PARAMETERS.ORGANIZATION_ID
         AND OE_ORDER_HEADERS_ALL.ORDER_TYPE_ID = OE_TRANSACTION_TYPES_TL.TRANSACTION_TYPE_ID
    and upper(oe_transaction_types_tl.description) not like '%SUP%'
         AND OE_ORDER_HEADERS_ALL.HEADER_ID = WSH_DELIVERY_DETAILS.SOURCE_HEADER_ID
         AND OE_ORDER_HEADERS_ALL.HEADER_ID = OE_ORDER_LINES_ALL.HEADER_ID
         AND OE_ORDER_LINES_ALL.LINE_ID = WSH_DELIVERY_DETAILS.SOURCE_LINE_ID
         AND TO_CHAR(WSH_DELIVERY_DETAILS.DELIVERY_DETAIL_ID ) = JA_IN_RG_I.REF_DOC_ID
         AND WSH_DELIVERY_DETAILS.DELIVERY_DETAIL_ID = WSH_DELIVERY_ASSIGNMENTS.DELIVERY_DETAIL_ID
         AND WSH_DELIVERY_ASSIGNMENTS.DELIVERY_ID = WSH_NEW_DELIVERIES.DELIVERY_ID
         AND WSH_NEW_DELIVERIES.DELIVERY_ID = WSH_DELIVERY_LEGS.DELIVERY_ID
         AND WSH_DELIVERY_LEGS.PICK_UP_STOP_ID = WSH_TRIP_STOPS.STOP_ID
         AND WSH_TRIP_STOPS.TRIP_ID                = WSH_TRIPS.TRIP_ID
    /* Input parameter can be either Invoice number or Delivery Id */
         AND (WSH_NEW_DELIVERIES.DELIVERY_ID = :DEL_ID OR JA_IN_RG_I.EXCISE_INVOICE_NUMBER = :INVOICE_NUMBER)
         AND NVL(WSH_DELIVERY_DETAILS.SHIPPED_QUANTITY,0) <>0
         AND     MTL_SYSTEM_ITEMS_B.ORGANIZATION_ID     = WSH_DELIVERY_DETAILS.ORGANIZATION_ID
         AND     MTL_SYSTEM_ITEMS_B.INVENTORY_ITEM_ID = WSH_DELIVERY_DETAILS.INVENTORY_ITEM_ID
         AND IC_TRAN_PND.LINE_DETAIL_ID               = WSH_DELIVERY_DETAILS.DELIVERY_DETAIL_ID
         AND     JSW_LOT_PACKSLIP.LOT_ID                    = IC_TRAN_PND.LOT_ID(+)
         AND     JSW_LOT_PACKSLIP.DELIVERY_ID          = WSH_NEW_DELIVERIES.DELIVERY_ID(+)
         AND      IC_TRAN_PND.LINE_ID                    = OE_ORDER_LINES_ALL.LINE_ID                                                  
         AND     IC_TRAN_PND.DELETE_MARK                = 0
         AND IC_TRAN_PND.COMPLETED_IND      = 1
         AND      IC_TRAN_PND.STAGED_IND                    =     1
         AND     P_FORM.CODE(+)                                   = substr(OE_ORDER_LINES_ALL.ORDERED_ITEM,3,2)
         AND     PR_TYPE.CODE                                   = substr(OE_ORDER_LINES_ALL.ORDERED_ITEM,1,2)
         AND     PR_TYPE.CODE                                   = P_FORM.PRD_TYPE_CODE
         AND     P_FORM.CODE                                   = substr(OE_ORDER_LINES_ALL.ORDERED_ITEM,3,2)
    AND     P_FORM.CODE                                   = PR_GRADE.PRD_FRM_CODE
         AND     PR_GRADE.CODE                                   = substr(OE_ORDER_LINES_ALL.ORDERED_ITEM,5,2)     
         AND     PR_GRADE.CODE                                   = PR_QTY.PRD_GRD_CODE
         AND     PR_QTY.CODE                                   = substr(OE_ORDER_LINES_ALL.ORDERED_ITEM,7,2)
         AND     PR_STL.PROD_CODE                              = PR_TYPE.CODE
         AND     PR_STL.QUALITY_LEVEL_CODE                    = PR_QTY.CODE
         AND     PR_STL.CODE                                   = substr(OE_ORDER_LINES_ALL.ORDERED_ITEM,9,2)
         AND rownum=1
    thanks,
    baskar.l

    Here is the explain plan
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | SELECT STATEMENT | | 1 | 920 | 12628 |
    | 1 | COUNT STOPKEY | | | | |
    | 2 | NESTED LOOPS | | 1 | 920 | 12628 |
    | 3 | NESTED LOOPS | | 1 | 728 | 12627 |
    | 4 | NESTED LOOPS | | 1 | 718 | 12626 |
    | 5 | NESTED LOOPS | | 1 | 684 | 12625 |
    | 6 | NESTED LOOPS | | 1 | 674 | 12624 |
    | 7 | NESTED LOOPS | | 1 | 665 | 12623 |
    | 8 | NESTED LOOPS | | 1 | 655 | 12622 |
    | 9 | NESTED LOOPS | | 1 | 532 | 12621 |
    | 10 | NESTED LOOPS | | 1 | 522 | 12620 |
    | 11 | FILTER | | | | |
    | 12 | NESTED LOOPS OUTER | | | | |
    | 13 | NESTED LOOPS | | 1 | 494 | 12617 |
    | 14 | NESTED LOOPS | | 1 | 477 | 12614 |
    | 15 | NESTED LOOPS | | 1 | 467 | 12611 |
    | 16 | NESTED LOOPS | | 1 | 382 | 12610 |
    | 17 | NESTED LOOPS | | 1 | 366 | 12609 |
    | 18 | NESTED LOOPS | | 1 | 321 | 12606 |
    | 19 | FILTER | | | | |
    | 20 | HASH JOIN OUTER | | | | |
    | 21 | TABLE ACCESS BY INDEX ROWID| IC_TRAN_PND | 1 | 22 | 3 |
    | 22 | NESTED LOOPS | | 1 | 292 | 12601 |
    | 23 | HASH JOIN | | 1 | 270 | 12598 |
    | 24 | NESTED LOOPS | | 4011 | 908K| 6272 |
    | 25 | HASH JOIN | | 4012 | 893K| 6272 |
    | 26 | TABLE ACCESS FULL | JSW_ITM_SEARCH_PRD_GRD | 33 | 759 | 2 |
    | 27 | HASH JOIN | | 20547 | 4113K| 6269 |
    | 28 | TABLE ACCESS FULL | JSW_ITM_SEARCH_QUALITY_LEVEL | 54 | 1296 | 2 |
    | 29 | HASH JOIN | | 24352 | 4304K| 6266 |
    | 30 | TABLE ACCESS FULL | JSW_ITM_SEARCH_PRD_TYP | 7 | 154 | 2 |
    | 31 | HASH JOIN | | 170K| 25M| 6260 |
    | 32 | TABLE ACCESS FULL | JSW_ITEM_SEARCH_SLITTING | 73 | 1971 | 2 |
    | 33 | HASH JOIN | | 44367 | 5719K| 6257 |
    | 34 | HASH JOIN | | 4469 | 410K| 367 |
    | 35 | TABLE ACCESS FULL| OE_TRANSACTION_TYPES_TL | 18 | 846 | 4 |
    | 36 | TABLE ACCESS FULL| OE_ORDER_HEADERS_ALL | 38240 | 1755K| 362 |
    | 37 | TABLE ACCESS FULL | OE_ORDER_LINES_ALL | 379K| 13M| 5761 |
    | 38 | INDEX UNIQUE SCAN | MTL_PARAMETERS_U1 | 1 | 4 | |
    | 39 | TABLE ACCESS FULL | WSH_DELIVERY_DETAILS | 579K| 21M| 5926 |
    | 40 | INDEX RANGE SCAN | IC_TRAN_PND_N1 | 2 | | 2 |
    | 41 | TABLE ACCESS FULL | JSW_ITM_SEARCH_PRD_FRM | 16 | 272 | 2 |
    | 42 | TABLE ACCESS BY INDEX ROWID | MTL_SYSTEM_ITEMS_B | 1 | 12 | 2 |
    | 43 | INDEX UNIQUE SCAN | MTL_SYSTEM_ITEMS_B_U1 | 1 | | 1 |
    | 44 | TABLE ACCESS BY INDEX ROWID | JA_IN_RG_I | 1 | 45 | 3 |
    | 45 | INDEX RANGE SCAN | JA_IN_RG_I_N3 | 1 | | 2 |
    | 46 | TABLE ACCESS BY INDEX ROWID | HZ_CUST_ACCOUNTS | 1 | 16 | 1 |
    | 47 | INDEX UNIQUE SCAN | HZ_CUST_ACCOUNTS_U1 | 1 | | |
    | 48 | TABLE ACCESS BY INDEX ROWID | HZ_PARTIES | 1 | 85 | 1 |
    | 49 | INDEX UNIQUE SCAN | HZ_PARTIES_U1 | 1 | | |
    | 50 | TABLE ACCESS BY INDEX ROWID | WSH_DELIVERY_ASSIGNMENTS | 1 | 10 | 3 |
    | 51 | INDEX RANGE SCAN | WSH_DELIVERY_ASSIGNMENTS_N3 | 1 | | 2 |
    | 52 | TABLE ACCESS BY INDEX ROWID | JSW_LOT_PACKSLIP | 1 | 17 | 3 |
    | 53 | INDEX RANGE SCAN | JSW_LOT_PACKSLIP_N1 | 1 | | 2 |
    | 54 | TABLE ACCESS BY INDEX ROWID | WSH_NEW_DELIVERIES | 1 | 18 | 1 |
    | 55 | INDEX UNIQUE SCAN | WSH_NEW_DELIVERIES_U1 | 1 | | |
    | 56 | TABLE ACCESS BY INDEX ROWID | WSH_DELIVERY_LEGS | 1 | 10 | 2 |
    | 57 | INDEX RANGE SCAN | WSH_DELIVERY_LEGS_N1 | 1 | | 1 |
    | 58 | TABLE ACCESS BY INDEX ROWID | WSH_TRIP_STOPS | 1 | 10 | 1 |
    | 59 | INDEX UNIQUE SCAN | WSH_TRIP_STOPS_U1 | 1 | | |
    | 60 | TABLE ACCESS BY INDEX ROWID | WSH_TRIPS | 1 | 123 | 1 |
    | 61 | INDEX UNIQUE SCAN | WSH_TRIPS_U1 | 1 | | |
    | 62 | TABLE ACCESS BY INDEX ROWID | HZ_CUST_SITE_USES_ALL | 1 | 10 | 1 |
    | 63 | INDEX UNIQUE SCAN | HZ_CUST_SITE_USES_U1 | 1 | | |
    | 64 | TABLE ACCESS BY INDEX ROWID | HZ_CUST_ACCT_SITES_ALL | 1 | 9 | 1 |
    | 65 | INDEX UNIQUE SCAN | HZ_CUST_ACCT_SITES_U1 | 1 | | |
    | 66 | TABLE ACCESS BY INDEX ROWID | HZ_CUST_SITE_USES_ALL | 1 | 10 | 1 |
    | 67 | INDEX UNIQUE SCAN | HZ_CUST_SITE_USES_U1 | 1 | | |
    | 68 | TABLE ACCESS BY INDEX ROWID | HZ_CUST_ACCT_SITES_ALL | 1 | 34 | 1 |
    | 69 | INDEX UNIQUE SCAN | HZ_CUST_ACCT_SITES_U1 | 1 | | |
    | 70 | TABLE ACCESS BY INDEX ROWID | HZ_PARTY_SITES | 1 | 10 | 1 |
    | 71 | INDEX UNIQUE SCAN | HZ_PARTY_SITES_U1 | 1 | | |
    | 72 | TABLE ACCESS BY INDEX ROWID | HZ_LOCATIONS | 1 | 192 | 1 |
    | 73 | INDEX UNIQUE SCAN | HZ_LOCATIONS_U1 | 1 | | |
    we need to tune this query to reduce it time of execution as our users are very much affected in running requests.
    thanks,
    baskar.l

  • Help in writing a query!

    Dear All,
    My database is 11gR2 on Linux.
    I am struck in writing a difficult query, need help from your guys.
    I have a table, an application is controlling the columns of this table. Columns are added by the application.
    This is the structure of the table:
    create table imran_test(
    2 username varchar2(100),
    3 layer1 number(1),
    4 layer2 number(2),
    5 layer3 number(2));
    -- where layer1, layer2, layer3.... are increased up to layer 22 and could be increased more...
    Now each username will have 1 in any one of the layer, and all other layers will have 0
    Like if I consider the above table this could be the sample data:
    imran 1 0 0
    hafeez 0 1 0
    james 0 0 1
    Now the result my query should return is:
    select username, <column name where value is 1> and value of it, as per sample data, this should be return by the query:
    imran layer1 1
    hafeez layer2 1
    james layer 3 1
    Note: Please remember the columns are not fixed, they are added/altered by application.
    Regards,
    Imran

    The table design is incorrect as it is not in 3NF and has a repeating group
    You should correct the 'design' first or turn the layer... columns in a VARRAY.
    Also my feeling is you should change your subject line 'Help in writing a query!' in 'Write my query' as that is what you actually ask, and leave out the exclamation mark.
    Basically you dump everything in this forum, and being a bit less demanding might suit you better.
    Also you still act rude by not marking your questions as answered.
    Change that
    Sybrand Bakker
    Senior Oracle DBA
    Edited by: sybrand_b on 1-apr-2012 12:09

  • Help in group by query

    Hi,
    Please help me in the following query.
    SELECT
    a.bcast_id ,
    a.bcast_file_nm ,
    a.clickthru_url_cd ,
    a.list_id ,
    a.prs_id ,
    a.resp_cd ,
    a.run_seq ,
    COUNT(a.resp_cd) ,
    c.src_grp_cd ,
    b.site_cd
    FROM
    gca_cbx_response_test a ,
    gca_program_run_hist b ,
    campaign_master c
    WHERE
    a.list_id=b.list_id
    AND
    a.run_seq=b.campaign_run_seq
    AND
    b.campaign_cd=c.campaign_cd
    GROUP BY
    a.bcast_id ,
    a.bcast_file_nm ,
    a.clickthru_url_cd ,
    a.list_id ,
    a.prs_id ,
    a.resp_cd ,
    a.run_seq ,
    c.src_grp_cd ,
    b.site_cd
    HAVING
    a.resp_ts
    BETWEEN
    to_date('04-AUG-2005 00:01:32','DD-MON-YYYY HH24:MI:SS')
    AND
    to_date('04-AUG-2005 00:01:32','DD-MON-YYYY HH24:MI:SS');
    But the following group by query is throwing error that a.resp_ts is not a group by function.
    But i don't want to add a.resp_ts in group by clause.
    Please help me in this query.
    Thanks,
    Dilip

    How about:
    SELECT a.bcast_id ,
           a.bcast_file_nm ,
           a.clickthru_url_cd ,
           a.list_id ,
           a.prs_id ,
           a.resp_cd ,
           a.run_seq ,
           COUNT(a.resp_cd) ,
           c.src_grp_cd ,
           b.site_cd
    FROM   gca_cbx_response_test a ,
           gca_program_run_hist b ,
           campaign_master c
    WHERE  a.list_id=b.list_id
    AND    a.run_seq=b.campaign_run_seq
    AND    b.campaign_cd=c.campaign_cd
    AND    a.resp_ts BETWEEN to_date('04-AUG-2005 00:01:32','DD-MON-YYYY HH24:MI:SS')
                     AND to_date('04-AUG-2005 00:01:32','DD-MON-YYYY HH24:MI:SS');
    GROUP BY a.bcast_id ,
             a.bcast_file_nm ,
             a.clickthru_url_cd ,
             a.list_id ,
             a.prs_id ,
             a.resp_cd ,
             a.run_seq ,
             c.src_grp_cd ,
             b.site_cd;

Maybe you are looking for

  • Adding zip file to classpath or -Xbootclasspath on J9

    Hi, I'm trying to add a zip file containing javax classes (jscience-vm14.zip) to the classpath when running my program. I haven't had any problems adding jar files for instance, but I can't seem to have this zip file included so that it can be recogn

  • Passbook not showing up in lock screen at Starbucks.

    I added my Starbucks card (via the Starbucks app) into Passbook. I also added several "favorite locations" to the card.  I have all necessary settings, including those in Notifications and Location Services, turned on as described in http://support.a

  • FB01 authorization needs to be blocked in foreground

    Dear Friends, Our SOX team's requirement is to remove authorization of FB01 for everyone.  Nobody should be able to run FB01.  But, all other Transaction Codes which use FB01 in the back ground should work if the authorization is given to that partic

  • HT4527 I would like to move my itunes libary.

    I have recently got a new laptop and want to move my music, pictures, and movies from my old laptop to my new one. My new laptop has the new iTunes and Windows 8. I have tried Home Sharing, but it will not connect both my devices. How can I move ever

  • Add the new item through the Bapi 'bapi_outb_delivery_change'

    I want to add the new item to the existing outbound delivery.How to add the new item in the bapi 'bapi_outb_delivery_change'. Please provide me the code for the bapi 'BAPI_OUTB_DELIVERY_CHANGE' to add the new item.