Help on writing this query.

Hi Folks,
I'm trying to write a query to retrive the following information regarding snapshots. I tried lot of ways and couldn't get the solutions so seeking your help...
Can you send me a query that will give me all this information.
db name of snapshot site
snapshot name and their base table
refresh type (if it is fast, please list he snapshot log used)
refresh group which snapshot belongs to
dbms_job number which perform the refresh, job current status
refresh frequency
last refresh time
thanks
Karthik

If you tried a lot of ways ... post your work and show us what you have done.
What you are being asked to do is query data dictionary views. Do you know which ones?
SELECT view_name
FROM all_views
WHERE view_name LIKE '%<you fill this in>%';That is all the hints you get until you show your work.

Similar Messages

  • Hi need help in writing this query

    A table has three columns - id (primary key), categoryID (numeric) and
    amount (numeric). The goal is to provide a query that would show categoryID
    and sum of amounts within that category where categoryID is an odd number
    and sum of amounts is greater than 100,000

    select categoryid,sum(amount) from table where mod(categoryid,2)=1
    group by categoryid
    having sum(amount) > 100000
    Regards,
    Yuri
    [http://it.toolbox.com/blogs/living-happy-oracle]

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

  • Help to Simplify this query

    i am using
    Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
    With the Partitioning option
    JServer Release 8.1.7.4.0 - Production
    Please help to simplify this query. I also want to make this as a procedure.
    select
    RH.resort as RH_RESORT,
    RH.rate_code as RH_RATE_CODE,
    RD.rate_detail_id as RD_RATE_DETAIL_ID,
    RD.rate1 as RD_RATE1,
    RD.rate2 as RD_RATE2,
    RD.rate3 as RD_RATE3,
    RD.rate4 as RD_RATE4,
    RD.rate5 as RD_RATE5,
    RRC.room_category as RM_CAT,
    initcap(RRMCAT.long_description) as RM_DESC,
    RH.DAY1,
    RH.DAY2,
    RH.DAY3,
    RH.DAY4,
    RH.DAY5,
    RH.DAY6,
    RH.DAY7,
    RH.WEEKEND1,
    RH.WEEKEND2,
    RH.WEEKEND3,
    RH.WEEKEND4,
    RH.WEEKEND5,
    RH.WEEKEND6,
    RH.WEEKEND7
    from pms_rate_header RH,
    pms_rate_detail RD,
    pms_rate_room_cat RRC,
    resort_room_category RRMCAT
    where RH.inactive_date is NULL
    and RH.RESORT='FABGOI'
    and RH.RATE_CODE ='CRRRACK'
    and ('15-Jan-2007' >= RH.BEGIN_DATE
    and '16-Jan-2007' <= RH.END_DATE)
    and RD.rate_header_id=RH.rate_header_id
    and RD.inactive_date is NULL
    and ('15-Jan-2007' >= RD.BEGIN_DATE
    and '16-Jan-2007' <= RD.END_DATE)
    and RRC.rate_detail_id=RD.rate_detail_id
    and RRC.resort=RH.resort
    and RRMCAT.resort=RH.resort
    and RRMCAT.room_category=RRC.room_category
    and RRC.inactive_date is NULL
    and RRMCAT.inactive_date IS NULL
    regards
    lee1212

    where RH.inactive_date is NULL
    and RH.RESORT='FABGOI'
    and RH.RATE_CODE ='CRRRACK'
    and ('15-Jan-2007' >= RH.BEGIN_DATE
    and '16-Jan-2007' <= RH.END_DATE)
    and RD.rate_header_id=RH.rate_header_id
    and RD.inactive_date is NULL
    and ('15-Jan-2007' >= RD.BEGIN_DATE
    and '16-Jan-2007' <= RD.END_DATE)
    and RRC.rate_detail_id=RD.rate_detail_id
    and RRC.resort=RH.resort
    and RRMCAT.resort=RH.resort
    and RRMCAT.room_category=RRC.room_category
    and RRC.inactive_date is NULL
    and RRMCAT.inactive_date IS NULL
    in the above part i am finding repeated joins and lot of 'and's
    i want to know any line can be eliminated or the the query can be rewritten in a simple way without affecting it's accuracy?
    regards
    Lee1212

  • Plz help me design this query

    Hi,
    Can you’ll please help me with this query.
    Here is a little bit of background:
    One title can have multiple items associated with it.
    Table: TITLE has the master list of titles. TITLE_ID is the primary key.
    Table: ITEM has the master list of all items. ITEM_ID is the primary. This table also has the TITLE_ID which stores title for this item.
    Table: ITEM_STATUS has fields ITEM_ID and STATUS_ID. This field contains statuses for items. But not all items contained in the table ITEM are in this table.
    I want to find TITLE_ID’s whose all items (all ITEM_ID in table ITEM having same value for TITLE_ID) have a particular status (for example STATUS_ID = 2) in table ITEM_STATUS.
    Let’s say TITLE_ID = 1 has 5 items in table ITEM_ID and only 4 items out of it in table ITEM_STATUS with STATUS_ID = 2, then this TITLE_ID should not come. OR
    Let’s say TITLE_ID = 1 has 5 items in table ITEM_ID and all these 5 items are in table ITEM_STATUS but only 1 has STATUS_ID = 2, then this TITLE_ID should also not come
    In the above case only if all 5 items are contained in table ITEM_STATUS have STATUS_ID = 2 then this TITLE_ID should be reported by the query.
    What should be the query like for this one, I am fairly new to SQL so plz guide me.
    Thank you,
    Raja

    I haven't tested the query below. Try it and let me know for any issues:
    SELECT     DISTINCT t.title_id
         FROM     title t,
                        item i,
                        item_status its
    WHERE     t.title_id = i.title_id
         AND     i.item_id = its.item_id
         AND     NOT EXISTS     (
                                                           SELECT 1
                                                                FROM item_status its1
                                                           WHERE its1.item_id = i.item_id
                                                                AND status_id <> 'YOUR_ITEM_STATUS'
                                                      )

  • Please help to modifiy this query for better performance

    Please help to rewrite this query for better performance. This is taking long time to execute.
    Table t_t_bil_bil_cycle_change contains 1200000 rows and table t_acctnumberTab countains  200000 rows.
    I have created index on ACCOUNT_ID
    Query is shown below
    update rbabu.t_t_bil_bil_cycle_change a
       set account_number =
           ( select distinct b.account_number
             from rbabu.t_acctnumberTab b
             where a.account_id = b.account_id
    Table structure  is shown below
    SQL> DESC t_acctnumberTab;
    Name           Type         Nullable Default Comments
    ACCOUNT_ID     NUMBER(10)                            
    ACCOUNT_NUMBER VARCHAR2(24)
    SQL> DESC t_t_bil_bil_cycle_change;
    Name                    Type         Nullable Default Comments
    ACCOUNT_ID              NUMBER(10)                            
    ACCOUNT_NUMBER          VARCHAR2(24) Y    

    Ishan's solution is good. I would avoid updating rows which already have the right value - it's a waste of time.
    You should have a UNIQUE or PRIMARY KEY constraint on t_acctnumberTab.account_id
    merge rbabu.t_t_bil_bil_cycle_change a
    using
          ( select distinct account_number, account_id
      from  rbabu.t_acctnumberTab
          ) t
    on    ( a.account_id = b.account_id
           and decode(a.account_number, b.account_number, 0, 1) = 1
    when matched then
      update set a.account_number = b.account_number

  • Could you please help me make this query less complicated

    could you please help me make this query less complicated
    select t1.R_OBJECT_ID
    from dm_relation_sp a, ddt_resolution_sp t1
    where a.parent_id = '0900000283560456' -----------ID
    and a.child_id = t1.R_OBJECT_ID
    union all
    select t3.R_OBJECT_ID
    from ddt_resolution_sp t3
    where t3.R_OBJECT_ID in (select t2.child_id
    from dm_relation_sp t2
    where t2.parent_id in (select a.child_id
    from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
    where a.parent_id = '0900000283560456' -----------ID
    and a.child_id = t1.R_OBJECT_ID))
    union all
    select t4.R_OBJECT_ID
    from ddt_resolution_sp t4
    where t4.R_OBJECT_ID in(
    select t3.child_id from dm_relation_sp t3
    where t3.parent_id in (
    select t2.child_id
    from asud_fsk.dm_relation_sp t2
    where t2.parent_id in (select a.child_id
    from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
    where a.parent_id = '0900000283560456' -----------ID
    and a.child_id = t1.R_OBJECT_ID))
    and t3.relation_name = 'RESOLUTION_RELATION')
    union all
    select t5.R_OBJECT_ID
    from ddt_resolution_sp t5
    where t5.R_OBJECT_ID in
    (select t4.child_id
    from dm_relation_sp t4
    where t4.parent_id in(
    select t3.child_id from dm_relation_sp t3
    where t3.parent_id in (
    select t2.child_id
    from asud_fsk.dm_relation_sp t2
    where t2.parent_id in (select a.child_id
    from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
    where a.parent_id = '0900000283560456' -----------ID
    and a.child_id = t1.R_OBJECT_ID))
    and t3.relation_name = 'RESOLUTION_RELATION')
    and t4.relation_name = 'RESOLUTION_RELATION')
    Edited by: user13025450 on 29.04.2010 16:23

    Hi,
    Welcome to the forum! You'll find that there are many qualified people (such as Tubby) willing to help you. Will you do what you can to help them? In order to simplify the query you posted,someone will first have to understand what it does, what the tables that it uses are like, and what tools you have to work with (that is, what version of Oracle, and any other software you are using). To actually test their ideas, people will need versions of your tables.
    Many people, if they spent enough time, might be able to figure out roughly what you are doing, make some tables themselves and test a solution. You can help with all of that. I assume you already know what the appliction is, and what this particular query is supposed to do: you don't have to figure out any of that, you just have to say it. You know what all your tables are, what the datatypes of all the columns are, and what kinds of data are in the tables: you don't have to guess at any of that.
    Describe what you're doing. Think about it: how do we know that
    SELECT  NULL
    FROM    dual;doesn't do what you want?
    Post CREATE TABLE and INSERT statements for a little sample data.
    Post the results that this query is supposed to produce from those results. (Is it producing the right output now? Then it should be easy to post the correct results.)
    Describe, as well as you can, how the present query is doing it.
    Format your existing code, so it's easy to see what the different branches of the UNION are, and what the main clauses are in each one.
    When posting formatted text (code or results) type these 6 characters
    \(all small letters, inside curly brackets) before and after each formatted section, to keep this site from compressing the spaces.
    Say what versions of Oracle (e.g. 10.2.0.3.0) and any other relevant software you are using.
    I know it's a lot of work, but it really helps. You can do it as well (probably better) than anyone else, and if you're unwilling to do it, why should anyone else be willing?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Help with re-writing this query

    Dear experts;
    create table t2
      ID varchar2(1000),
      name varchar2(1000),
       place varchar2(1000)
    create table mappingt2
      grades varchar2(1000)
      individual varchar2(1000)
    insert into t2 values ('James', 'John', 'newyork');
    insert into t2 values ('Linda', 'James', 'London');
    insert into t2 values ('Alex', 'kim', 'Mexico');
    insert into t2 values ('karen', 'Jack', 'Tunis');
    insert into t2 values ('CC', 'Jack', 'Peru');
    insert into t2 values ('Linda', 'James', 'Germany');
    insert into mappingt2 values ('A', 'James');
    insert into mappingt2 values ('C', 'Kim');
    insert into mappingt2 values ('C', 'Linda');
    insert into mappingt2 values ('B', 'CC');I have the following query below
    SELECT (select grades from mappingt2 t
       where t.individual =  pt.ID) as current_grade
          ,(select grades from mappingt2 ty
       where ty.individual =  pt.name) alt_grade
          ,pt.place
      FROM t2 ptI was just wondering whether this query can be better written. All help is appreciated. Thank you

    user13328581 wrote:
    Hi Frank, Tom Kyte claims sub scalar queries is usually betterHe didn't say usually he said if you want the first row faster
    >
    if your goal is to optimize your query for initial response time, you may want to use the former query, with the scalar subquery, because Oracle Database would have to get just the first row from DEPT, run the scalar subquery (select count...) against EMP to get the count, and then return it. The process for returning that first row would be very fast.
    >
    The corollary to this that was not explicitly mentioned in the article that I can see is that this probably comes at the expense of the time taken to return all the rows which can then take longer.

  • Is there any better way of writing this query??

    I have a query on insert which looks like this,
    INSERT INTO TEMP( I1,I2)
    SELECT TI1 FROM CLIENT1
    WHERE R_CD ='PR' OR 'SR',
    SELECT TI2 FROM CLIENT2
    WHERE R_CD = 'MN' OR 'OP
    There are two tables where the source data is coming from and inserted into TEMP table. I find this query to be inefficient. Anybody who can help me writing a good one?? Thanks.

    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by [email protected]:
    I have a query on insert which looks like this,
    INSERT INTO TEMP( I1,I2)
    SELECT TI1 FROM CLIENT1
    WHERE R_CD ='PR' OR 'SR',
    SELECT TI2 FROM CLIENT2
    WHERE R_CD = 'MN' OR 'OP
    There are two tables where the source data is coming from and inserted into TEMP table. I find this query to be inefficient. Anybody who can help me writing a good one?? Thanks.<HR></BLOCKQUOTE>
    A possible solution,
    INSERT INTO TEMP( I1,I2)
    SELECT C1.TI1, C2.TI2
    FROM CLIENT1 C1, CLIENT2 C2
    WHERE (C1.R_CD = 'PR' OR C1.R_CD ='SR') AND
    (C2.R_CD = 'MN' OR C2.R_CD = 'OP')
    null

  • Query Issue in Creating a View....Please help me with this query..

    I would like to create a view on this table with four columns
    1. PN#_EXP_DATE
    2. PN#
    3. PN#_EFF_DATE
    4. PN#
    P_S_C     A_C     P     EXP_DT
    21698     13921     1     5/29/2009 3:15:41 PM     
    21698     13921     1     5/29/2009 3:54:57 PM     
    21698     1716656     4     5/29/2009 3:15:41 PM     
    21698     3217     3     5/29/2009 3:15:40 PM     
    21698     3217     3     5/29/2009 3:54:57 PM     
    21698     60559     2     5/29/2009 3:15:41 PM     
    21698     60559     2     5/29/2009 3:54:57 PM     
    I have a trigger on A, which inserts the DML records into B. (Table A and B structure is the almost the same,
                                       where table B will have one extra column exp_dt)
    NOw Table B can have records with same P_S_C and A_C columns and exp_dt will capture the history.
    for example: from the above sample data, let us take first two records..
    P_S_C     A_C     P     EXP_DT
    21698     13921     1     5/29/2009 3:15:41 PM     --- Record 1
    21698     13921     1     5/29/2009 3:54:57 PM     --- Record 2
    from this..
    Note: 1. Table A and Table C can be joined using A.P_S_C and C.R_C to get the start_date.
    2. PN# comes from table D. It contains numbers for the resp. weeks.
    3. PN#_EFF_DATE is the previous immediate previous date for that record in history table (Table B).
    I wanted the data like..
    ---- this is for the second record in the above..
    PN#_EXP_DATE PN# PN#_EFF_DATE PN#
    5/29/2009 3:54:57 PM     214 5/29/2009 3:15:41 PM     214
    ---- this is for the first record in the above..
    PN#_EXP_DATE PN# PN#_EFF_DATE PN#
    5/29/2009 3:54:41 PM     214 ( for this we should query the table C to get the
                        start_date, for this combinatation of P_S_C and A_C in table B
                             where B.P_S_C = C.A_C
                             and that value should be the EFF_DT for this record)
    Please help me with this....
    Thanks in advance..

    Hi All,
    select d.P# as "PN#_EXP_DATE", exp_date
    from daily_prd d, cbs1_assoc_hist b
    where to_char(d.day_date,'MM/DD/YYYY') = to_char(b.exp_date,'MM/DD/YYYY')
    and d.period_type = 'TIMEREPORT';
    This above query gives the output as follows:
    pn#_exp_date exp_date
    214     5/29/2009 3:15:40 PM
    214     5/29/2009 3:15:41 PM
    214          5/29/2009 3:15:41 PM
    214          5/29/2009 3:15:41 PM
    214          5/29/2009 3:54:57 PM
    214          5/29/2009 3:54:57 PM
    214          5/29/2009 3:54:57 PM
    This below is the data from history table (Table B).
    P_S_C     A_C PLACE EXP_DATE
    21698          3217          3     5/29/2009 3:15:40 PM     
    21698          13921          1     5/29/2009 3:15:41 PM     
    21698          1716656          4     5/29/2009 3:15:41 PM     
    21698          60559          2     5/29/2009 3:15:41 PM     
    21698          13921          1     5/29/2009 3:54:57 PM     
    21698          3217          3     5/29/2009 3:54:57 PM     
    21698          60559          2     5/29/2009 3:54:57 PM     
    I got the pn#_exp_date from the Table 'D', for the given exp_date from Table B.
    My question is again....
    CASE - 1
    from the given records above, I need to look for exp_date for the given same P_S_C and A_C.
    in this case we can take the example...
    P_S_C     A_C PLACE EXP_DATE
    21698          3217          3     5/29/2009 3:15:40 PM
    21698          3217          3     5/29/2009 3:54:57 PM
    In this case, the
    pn#_exp_date exp_date     pn#_eff_date eff_date
    214     5/29/2009 3:15:57 PM     < PN# corresponding to the     5/29/2009 3:15:40 PM
                        eff_date .>
                        <Basically the eff_date is
                        nothing but the exp_date only.
                        we should take the immediate before one.
    In this case, our eff_date is '5/29/2009 3:15:40 PM'.
    but how to get this.
    CASE - 2
    from the above sample data, consider this
    P_S_C     A_C PLACE EXP_DATE
    21698     1716656     4     5/29/2009 3:15:41 PM
    In this case, there is only one record for the P_S_C and A_C combination.
    The expected result :
    pn#_exp_date exp_date               pn#_eff_date eff_date
    214     5/29/2009 3:15:41 PM     < PN# corresponding to the     5/29/2009 3:15:40 PM
                        eff_date .>
                   <Basically the eff_date is
                   nothing but the exp_date only.
                        we should take the immediate before one.
    In this case to get the eff_date, we should query the Table 'C', to get the eff_date, which is START_DT column in this table.
    for this join B.P_S_C and C.R_C.
    Hope I am clear now..
    Thanks in advance.....

  • Help in Tuning this Query

    Hi,
    I have a query in my proj where the same table is looked up twice in the same query.
    Can anybody suggest in improving the performance of this query?
    select * from table1 a1 where (a1.column1, a1.column2, a1.column3, a1.column4, a1.column5, a1.column6, a1.column7, a1.column8, a1.column9,
    a1.column10) in ( select a2.column1, a2.column2, a2.column3, a2.column4, a2.column5, a2.column6, a2.column7, a2.column8, a2.column9,
    a2.column10 from table1 a2 where column20 = '<condn>')
    The table1 used here is same in outer query as well as the sub query. this is a example of what we use here, and the table1 contains 30 million rows. Though, creating index with 10 columns can be a option, we already have a unique index with 11 columns(which includes 10 from this query) and will that be helpful in anyway? or the same existing index can be forced?
    Thanks a lot for ur time

    Depending on the selectivity of column20 I am not sure Index is the best way to go. It might perform better with two full scans and a hash-join.
    Anyway, I do prefer the syntax:
    select /*+ leading(a2) */ a1.*
    from table1 a1, table1 a2
    where a2.column20 = '<condn>'
    and a1.column1 = a2.column1
    and a1.column2 = a2.column2
    and  a1.column3 = a2.column3
    and  a1.column4 = a2.column4
    and  a1.column5 = a2.column5
    and  a1.column6 = a2.column6
    and  a1.column7 = a2.column7
    and  a1.column8 = a2.column8
    and  a1.column9 = a2.column9
    and  a1.column10 = a2.column10;I've added a leading hint to tell oracle that the start table is a2. Might be useless.
    Ensure your stats are up to date. You might need histograms here if your column20 is skewed.
    Hope this helps,
    François
    Edited by: Francois Berger on Oct 24, 2008 1:47 AM

  • Help on tuning this query

    Hi all i have this query:
    SELECT VTA.CO_VENDEDOR
    ,VTA.NB_VENDEDOR
    ,VTA.CO_CLASE_CLIENTE
    ,VTA.DE_CLASE_CLIENTE
    ,VTA.CO_CLIENTE
    ,VTA.NB_CLIENTE
    ,VTA.MN_VENDIDO
    ,NVL(DEV.MN_DEVUELTO,0) MN_DEVUELTO
    ,VTA.MN_VENDIDO - NVL(DEV.MN_DEVUELTO,0) MN_NETO_VENDIDO
    ,NVL(COB.MN_COBRADO,0) MN_COBRADO
    ,NVL(COB.MN_DESCUENTO,0) MN_DESCUENTO
    ,NVL(COB.MN_COBRADO,0) + NVL(COB.MN_DESCUENTO,0) MN_COBRADO_MAS_DESCUENTO
    FROM (SELECT FCL.CTV_CO_CLASE_ORGANIZACION CO_CLASE_CLIENTE
    ,FCL.CTV_DE_CLASE_ORGANIZACION DE_CLASE_CLIENTE
    ,FCL.CO_ORGANIZACION CO_CLIENTE
    ,FCL.ORG_NB_CLIENTE NB_CLIENTE
    ,FCL.PER_CO_IDENTIFICACION_VENDEDOR CO_VENDEDOR
    ,FCL.PER_NB_PRIMER_NOMBRE_VENDEDOR||' '||
    FCL.PER_NB_PRIMER_APELLIDO_VEND NB_VENDEDOR
    ,SUM((CA_PRODUCTO * (PR_PRODUCTO - NVL(PR_DESCUENTO_PRODUCTO,0))) * (1 - NVL(PC_DESCUENTO,0))) MN_VENDIDO
    FROM S04_FACTURA_CLIENTE_TOTAL_R FCL
    ,S04_FACTURA_CLIENTE_PRD_TOT FPR
         ,(SELECT FCP.FAC_ID_FACTURA
    ,SUM(DDC.MN_DEBITO_CREDITO) /
    SUM(FCP.CA_PRODUCTO * (FCP.PR_PRODUCTO - NVL(FCP.PR_DESCUENTO_PRODUCTO,0))) PC_DESCUENTO
         FROM S04_DOCUMENTO_DEBITO_CREDITO_R DDC
    ,S04_FACTURA_CLIENTE_PRD_TOT FCP
         WHERE DDC.ID_DOCUMENTO_REFERENCIA = FCP.FAC_ID_FACTURA
    AND DDC.TDC_IN_DEBITO_CREDITO = 'C'
    GROUP BY FCP.FAC_ID_FACTURA) DCT
    WHERE FCL.ID_REGISTRO = FPR.FAC_ID_FACTURA
    AND DCT.FAC_ID_FACTURA (+) = FPR.FAC_ID_FACTURA
    AND FCL.FE_EMISION BETWEEN to_date('01112009','ddmmyyyy') AND to_date('29112009','ddmmyyyy')
    AND FCL.ORG_ID_CLIENTE = NVL(NULL,FCL.ORG_ID_CLIENTE)
    AND FCL.PER_ID_VENDEDOR = NVL(7647771,FCL.PER_ID_VENDEDOR)
                   AND FCL.CTV_CO_ESTADO_DOCUMENTO = 'EM'
    AND FCL.UBG_ID_UBICACION_CLIENTE in (SELECT ID_REGISTRO
    FROM S00_UBICACION_GEOGRAFICA
    START WITH ID_REGISTRO = nvl(NULL, FCL.UBG_ID_UBICACION_CLIENTE)
    CONNECT BY PRIOR ID_REGISTRO = UBG_ID_UBICACION_PADRE)
    GROUP BY FCL.CTV_CO_CLASE_ORGANIZACION
    ,FCL.CTV_DE_CLASE_ORGANIZACION
    ,FCL.CO_ORGANIZACION
    ,FCL.ORG_NB_CLIENTE
    ,PER_CO_IDENTIFICACION_VENDEDOR
    ,PER_NB_PRIMER_NOMBRE_VENDEDOR||' '||
    PER_NB_PRIMER_APELLIDO_VEND) VTA
    ,(SELECT NDC .CTV_CO_CLASE_ORGANIZACION CO_CLASE_CLIENTE
    ,NDC.CTV_DE_CLASE_ORGANIZACION DE_CLASE_CLIENTE
    ,NDC.CO_CLIENTE
    ,NDC.ORG_NB_CLIENTE NB_CLIENTE
    ,FCL.PER_CO_IDENTIFICACION_VENDEDOR CO_VENDEDOR
    ,FCL.PER_NB_PRIMER_NOMBRE_VENDEDOR||' '||
    FCL.PER_NB_PRIMER_APELLIDO_VEND NB_VENDEDOR
    ,SUM(CA_PRODUCTO * (PR_PRODUCTO - NVL(PR_DESCUENTO_PRODUCTO,0))) MN_DEVUELTO
    FROM S06_NOTA_DEBITO_CREDITO_TOT_R NDC
         ,S06_DETALLE_NOTA_DEB_CRED_TOT DND
    ,S04_FACTURA_CLIENTE_TOTAL_R FCL
         WHERE NDC.ID_REGISTRO = DND.NDC_ID_NOTA_DEBITO_CREDITO
    AND NDC.CTV_CO_TIPO_DOCUMENTO = SK00_BUSCAR.F_VCT('CO_TIPO_DOCUMENTO_NOTA_CREDITO_FISCAL')
    AND NDC.CTV_CO_ESTADO_DOCUMENTO = SK00_BUSCAR.F_VCT('CO_ESTADO_DOCUMENTO_EMITIDO')
         AND NDC.FE_EMISION BETWEEN to_date('01112009','ddmmyyyy') AND to_date('29112009','ddmmyyyy')
         AND (NDC.CTV_CO_MOTIVO_NOTA = SK00_BUSCAR.F_VCT('CO_MOTIVO_NOE_DEVOLUCION')
         OR NDC.CTV_CO_MOTIVO_NOTA = SK00_BUSCAR.F_VCT('CO_MOTIVO_AJUSTE_PRECIO_NCD'))
    AND NDC.ORG_ID_CLIENTE = NVL(NULL,NDC.ORG_ID_CLIENTE)
    AND FCL.ID_REGISTRO = NDC.FAC_ID_FACTURA
                             AND FCL.CTV_CO_ESTADO_DOCUMENTO = 'EM'
    AND FCL.UBG_ID_UBICACION_CLIENTE in (SELECT ID_REGISTRO
    FROM S00_UBICACION_GEOGRAFICA
    START WITH ID_REGISTRO = nvl(NULL, FCL.UBG_ID_UBICACION_CLIENTE)
    CONNECT BY PRIOR ID_REGISTRO = UBG_ID_UBICACION_PADRE)
    GROUP BY NDC.CTV_CO_CLASE_ORGANIZACION
    ,NDC.CTV_DE_CLASE_ORGANIZACION
    ,NDC.CO_CLIENTE
    ,NDC.ORG_NB_CLIENTE
    ,FCL.PER_CO_IDENTIFICACION_VENDEDOR
    ,FCL.PER_NB_PRIMER_NOMBRE_VENDEDOR||' '||
    FCL.PER_NB_PRIMER_APELLIDO_VEND) DEV
    ,(SELECT RCD .CTV_CO_CLASE_ORGANIZACION CO_CLASE_CLIENTE
    ,RCD.CTV_DE_CLASE_ORGANIZACION DE_CLASE_CLIENTE
    ,RCD.CO_ORGANIZACION CO_CLIENTE
    ,RCD.ORG_NB_DISTRIBUIDOR NB_CLIENTE
    ,FCL.PER_CO_IDENTIFICACION_VENDEDOR CO_VENDEDOR
    ,FCL.PER_NB_PRIMER_NOMBRE_VENDEDOR||' '||
    FCL.PER_NB_PRIMER_APELLIDO_VEND NB_VENDEDOR
    ,SUM(RCD.MN_DESCUENTO) MN_DESCUENTO
    ,SUM(DECODE(SIGN(RCO.MN_COBRADO_ANTES - IVA.MN_IVA)
    ,-1
    ,RCD.MN_ABONO - ABS(RCO.MN_COBRADO_ANTES - IVA.MN_IVA)
    ,RCD.MN_ABONO)) MN_COBRADO
    FROM S06_RECIBO_COBRO_DOC_TOTAL_R RCD
    ,S04_FACTURA_CLIENTE_TOTAL_R FCL
    ,(SELECT ID_DOCUMENTO_REFERENCIA FAC_ID_FACTURA
    ,NVL(SUM(MN_DEBITO_CREDITO),0) MN_IVA
    FROM S04_DOCUMENTO_DEBITO_CREDITO_R
    WHERE TDC_CO_TIPO_DEBITO_CREDITO = SK00_BUSCAR.F_VCT('CO_TIPO_DEBITO_IVA')
    GROUP BY ID_DOCUMENTO_REFERENCIA) IVA
    ,(SELECT ID_REFERENCIA FAC_ID_FACTURA
    ,NVL(SUM(MN_ABONO),0) MN_COBRADO_ANTES
    FROM S06_RECIBO_COBRO_DOC_TOTAL_R
    WHERE FE_EMISION < to_date('01112009','ddmmyyyy')
    GROUP BY ID_REFERENCIA) RCO
         WHERE RCD.CTV_CO_ESTADO_DOCUMENTO = SK00_BUSCAR.F_VCT('CO_ESTADO_DOCUMENTO_EMITIDO')
         AND RCD.FE_EMISION BETWEEN to_date('01112009','ddmmyyyy') AND to_date('29112009','ddmmyyyy')
    AND RCD.ORG_ID_ORGANIZACION = NVL(NULL,RCD.ORG_ID_ORGANIZACION)
    AND FCL.CTV_CO_ESTADO_DOCUMENTO = 'EM'
                             AND FCL.ID_REGISTRO = RCD.ID_REFERENCIA
    AND FCL.UBG_ID_UBICACION_CLIENTE in (SELECT ID_REGISTRO
    FROM S00_UBICACION_GEOGRAFICA
    START WITH ID_REGISTRO = nvl(NULL, FCL.UBG_ID_UBICACION_CLIENTE)
    CONNECT BY PRIOR ID_REGISTRO = UBG_ID_UBICACION_PADRE)
    AND IVA.FAC_ID_FACTURA (+) = FCL.ID_REGISTRO
    AND RCO.FAC_ID_FACTURA (+) = FCL.ID_REGISTRO
    GROUP BY RCD.CTV_CO_CLASE_ORGANIZACION
    ,RCD.CTV_DE_CLASE_ORGANIZACION
    ,RCD.CO_ORGANIZACION
    ,RCD.ORG_NB_DISTRIBUIDOR
    ,FCL.PER_CO_IDENTIFICACION_VENDEDOR
    ,FCL.PER_NB_PRIMER_NOMBRE_VENDEDOR||' '||
    FCL.PER_NB_PRIMER_APELLIDO_VEND) COB
    WHERE VTA.CO_CLIENTE = DEV.CO_CLIENTE (+)
    AND VTA.CO_VENDEDOR = DEV.CO_VENDEDOR (+)
    AND VTA.CO_CLIENTE = COB.CO_CLIENTE (+)
    AND VTA.CO_VENDEDOR = COB.CO_VENDEDOR (+)
    ORDER BY VTA.NB_VENDEDOR
    ,VTA.CO_CLIENTE
    Is there a way i can influence the join method on this query ...?
    It's an XE DB.
    Regards, Luis ...!

    THIS IS THE PLAN:
    SQL> /
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=79006 Card=1 Bytes
    =253)
    1 0 SORT (ORDER BY) (Cost=79006 Card=1 Bytes=253)
    2 1 HASH JOIN (OUTER) (Cost=79005 Card=1 Bytes=253)
    3 2 HASH JOIN (OUTER) (Cost=78538 Card=1 Bytes=211)
    4 3 VIEW (Cost=78478 Card=1 Bytes=182)
    5 4 HASH (GROUP BY) (Cost=78478 Card=1 Bytes=232)
    6 5 FILTER
    7 6 HASH JOIN (OUTER) (Cost=78469 Card=1 Bytes=232
    8 7 TABLE ACCESS (BY INDEX ROWID) OF 'T04_FACTUR
    A_PRODUCTO' (TABLE) (Cost=2 Card=1 Bytes=46)
    9 8 NESTED LOOPS (Cost=25 Card=1 Bytes=213)
    10 9 VIEW OF 'V04_FACTURA_CLIENTE_TOTAL_R' (V
    IEW) (Cost=23 Card=1 Bytes=167)
    11 10 NESTED LOOPS (Cost=23 Card=1 Bytes=284
    12 11 NESTED LOOPS (OUTER) (Cost=23 Card=1
    Bytes=278)
    13 12 HASH JOIN (SEMI) (Cost=23 Card=1 B
    ytes=272)
    14 13 NESTED LOOPS (Cost=17 Card=1 Byt
    es=259)
    15 14 NESTED LOOPS (Cost=16 Card=1 B
    ytes=218)
    16 15 NESTED LOOPS (OUTER) (Cost=1
    6 Card=1 Bytes=212)
    17 16 NESTED LOOPS (Cost=15 Card
    =1 Bytes=179)
    18 17 NESTED LOOPS (Cost=15 Ca
    rd=1 Bytes=173)
    19 18 NESTED LOOPS (OUTER) (
    Cost=14 Card=1 Bytes=162)
    20 19 NESTED LOOPS (OUTER)
    (Cost=14 Card=1 Bytes=156)
    21 20 NESTED LOOPS (OUTE
    R) (Cost=14 Card=1 Bytes=150)
    22 21 NESTED LOOPS (OU
    TER) (Cost=14 Card=1 Bytes=144)
    23 22 NESTED LOOPS (
    Cost=14 Card=1 Bytes=105)
    24 23 SORT (UNIQUE
    ) (Cost=2 Card=1 Bytes=13)
    25 24 TABLE ACCE
    SS (FULL) OF 'T00_GRUPO_DATO_USUARIO_ACTIVO' (TABLE (TEMP))
    (Cost=2 Card=1 Bytes=13)
    26 23 TABLE ACCESS
    (BY INDEX ROWID) OF 'T04_FACTURA' (TABLE) (Cost=11 Card=1 B
    ytes=92)
    27 26 INDEX (RAN
    GE SCAN) OF 'I04_FAC_FE_EMISION' (INDEX) (Cost=10 Card=2)
    28 22 TABLE ACCESS (
    BY INDEX ROWID) OF 'T03_EMPRESA_SUCURSAL' (TABLE) (Cost=0 Ca
    rd=1 Bytes=39)
    29 28 INDEX (RANGE
    SCAN) OF 'I03_EMS_EMP' (INDEX) (Cost=0 Card=1)
    30 21 INDEX (UNIQUE SC
    AN) OF 'PK_PRY' (INDEX (UNIQUE)) (Cost=0 Card=1 Bytes=6)
    31 20 INDEX (UNIQUE SCAN
    ) OF 'PK_CAJ' (INDEX (UNIQUE)) (Cost=0 Card=1 Bytes=6)
    32 19 INDEX (UNIQUE SCAN)
    OF 'PK_PEC' (INDEX (UNIQUE)) (Cost=0 Card=1 Bytes=6)
    33 18 TABLE ACCESS (BY INDEX
    ROWID) OF 'T00_CONTENIDO_TABLA_VIRTUAL' (TABLE) (Cost=1 Car
    d=1 Bytes=11)
    34 33 INDEX (UNIQUE SCAN)
    OF 'PK_CTV' (INDEX (UNIQUE)) (Cost=0 Card=1)
    SORRY EXPLAIN OUTPUT TRUNCATED DUE TO SPACE RESTRICION .....
    Any help would be greatly appreciated.
    I believe there must be a way to influence on the tha costly HASH JOIN operation
    SQL> SPOOL OFF

  • Plz help me in this query for the tree

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

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

Maybe you are looking for

  • Attach JavaScript not working in Acrobat Reader XI

    Hello, I created a fillable PDF in which I used the following JavaScript for an "Attach" button:  this.importDataObject("MyFile"); This JavaScript worked and allowed the end user to attach files to the PDF in previous versions of Acrobat (through ver

  • Issue while passing Target URL dynamically in SOAP Receiver Adapter

    Experts, I am stuck with an issue while passing the Target URL dynamically. The UDF required for this works just fine. I can see the Target URL in Dynamic Configuration header(The Key is TServerLocation) in SXMB_MONI but the request that I am sending

  • Image gallery DELETE IMAGE function broken

    I followed the ADDT Basic Image gallery tutorial and everything was working flawlessly until I got to the delete image section. I added the 'delete image' information on the list_img.php page, and that is all linked correctly. on the delete_img.php p

  • Adobe 8.1.2 prints everything black

    Whether I am in the 3D viewer or document reader whatever I try to print comes out solid black. It is not the printer as I can copy and paste and print from a different program. Have checked all of the preferences and cannot come up with a solution.

  • Do you install both zendcore and php? Or does the Zend include a php 5 rls?

    This quite unclear. When installing Zencore for Oracle. Do I also need to install php 5 sperately? First before installing Zendcore. Or does the Zendcore package include php 5? Anyone, please help. Pete