Nulls in join...

I have an application which I need to modify to support an additional class of product.
Specifically the new products have the same structure as the old ones, except they have one variant for each region.
The obvious thing to do is add an extra field in the key.
So
PRODUCT_CODE
-->
PRODUCT_CODE, REGION
where region may be null to accomodate the older product.
The problem is I know (believe) that
REGION = REGION is false when both are null.
Can I set something that says, treat NULL = NULL as true?
Or is there a better way of doing this? (I guess I could have a 'virtual region' 'THEWORLD' and have all the old ones in there?
Iain

You are correct, NULL will never equal NULL. There is no setting in Oracle to change this behavior, Oracle will always be consistent about its treatment of NULL values.
Without knowing more, having a 'WORLDWIDE' region for the existing products would seem like the simplest approach. There may be some benefit to breaking out a separate region-availability table and placing the constraint on that table.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC

Similar Messages

  • How to relate two tables when there is null in join criteria

    Hi,
    I have two tables dept and emp, they both are joined on basis of deptno. few records in emp table have no deptno. i want to join these tables, i want to count those records as well where deptno is null in emp table. Please can anybody help me to get this query.
    Regards,

    Please refer...
    http://download-west.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm#i2054062
    and search 'Using Outer Joins: Examples'
    http://download-west.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_10002.htm#i2066378

  • Multiple rows Converge to Single row and join

    Hi Folks,
    I am facing a tricky challenge to join a table with multiple rows and converge into a single row (based on ID, period) and join with another table to get a single row. Let me explain.
    Table 1: DTL_TABLE (id, period, course, names, title, type)
    1 2010 mat john null null
    1 2010 mat jim null null
    1 2010 cam null officer null
    1 2010 cam null Prof null
    1 2010 phy null null Inclass
    1 2010 phy null null Online
    Join with
    Table 2: ID_TABLE(id, period, Loc, Dept, Code)
    1 2010 nj 101 CC.
    Output format (id, period, course, names, title, type, Loc, Dept, Code)
    result : 1 2010 mat,cam,phy john,jim officer,prof inclass,online nj 101 CC
    I have created all the DDLs and DMLs if that help. Kindly let me know if a Join SQL query is possible.
    Thank you,
    Aj
    CREATE TABLE DTL_TABLE
       ids      VARCHAR2 (10),
       period   VARCHAR2 (10),
       course   VARCHAR2 (10),
       names    VARCHAR2 (10),
       title    VARCHAR2 (10),
       TYPE     VARCHAR2 (10)
    INSERT INTO DTL_TABLE
         VALUES ('1',
                 '2010',
                 'mat',
                 'jim',
                 NULL,
                 NULL);
    INSERT INTO DTL_TABLE
         VALUES ('1',
                 '2010',
                 'mat',
                 'john',
                 NULL,
                 NULL);
    INSERT INTO DTL_TABLE
         VALUES ('1',
                 '2010',
                 'mat',
                 'kale',
                 NULL,
                 NULL);
    INSERT INTO DTL_TABLE
         VALUES ('1',
                 '2010',
                 'cam',
                 NULL,
                 'officer',
                 NULL);
    INSERT INTO DTL_TABLE
         VALUES ('1',
                 '2010',
                 'cam',
                 NULL,
                 'prof',
                 NULL);
    INSERT INTO DTL_TABLE
         VALUES ('1',
                 '2010',
                 'phy',
                 NULL,
                 NULL,
                 'inclass');
    INSERT INTO DTL_TABLE
         VALUES ('1',
                 '2010',
                 'phy',
                 NULL,
                 NULL,
                 'online');
    COMMIT;
    CREATE TABLE id_table
       ids      VARCHAR2 (10),
       period   VARCHAR2 (10),
       loc      VARCHAR2 (10),
       dept     VARCHAR2 (10),
       code     VARCHAR2 (10)
    INSERT INTO id_table
         VALUES ('1',
                 '2010',
                 'nj',
                 '101',
                 'cc');
    COMMIT;

    Aj09 wrote:
    Hi Folks,
    I am facing a tricky challenge to join a table with multiple rows and converge into a single row (based on ID, period) and join with another table to get a single row. Let me explain.
    Table 1: DTL_TABLE (id, period, course, names, title, type)
    1 2010 mat john null null
    1 2010 mat jim null null
    1 2010 cam null officer null
    1 2010 cam null Prof null
    1 2010 phy null null Inclass
    1 2010 phy null null Online
    Join with
    Table 2: ID_TABLE(id, period, Loc, Dept, Code)
    1 2010 nj 101 CC.
    Output format (id, period, course, names, title, type, Loc, Dept, Code)
    result : 1 2010 mat,cam,phy john,jim officer,prof inclass,online nj 101 CC
    I have created all the DDLs and DMLs if that help. Kindly let me know if a Join SQL query is possible.
    SELECT TBL.id,
           DTLperiod,
           course,
           names,
           title,
           TYPE,
           Loc,
           Dept,
           Code
    FROM   ID_TABLE TBL,
           DTL_TABLE DTL
    WHERE  TBL.ID = DTL.ID
           AND TBL.PERIOD = DTL.PERIOD; it not good to use RESERVED WORDS like "ID" or "TYPE" as column names

  • Left joins on multi-million rows

    i have a simple query doing left joining on several tables, upward of 7 tables. each table has several hundred million rows.
    tblA is 1:M tblB and tblB is 1:M tblC and so on.
    how to tune a query liked that?
    sample query is
    select distinct
    a.col,b.col,c.col
    from tblA a left join tblB b
    on a.id=b.id
    and a.col is not null
    left join tblC
    on b.id=c.id
    and c.col > criteria
    thanks.

    hi
    a simple query is liked
    SELECT my_DEP.description,
    my_DEP.addr_id,
    hundredRowsTbl.address,
    5MillTbl.checkin_TIME,
    5MillTbl.checkout_TIME,
    hundredRowsTbl.ID2,
    5MillTbl.ID,
    5MillTbl.col2,
    my_DEP.col3,
    5MillTbl.col13,
    hundreds.desc,
    50mmTbl.col6,
    50mmTbl.col5,
    5MillTbl.col33
    FROM
    my.5MillTbl 5MillTbl
    LEFT OUTER JOIN
    my.50mmTbl 50mmTbl
    ON 5MillTbl.ID = 50mmTbl.ID
    LEFT OUTER JOIN my.hundreds hundreds
    ON 5MillTbl.banding =
    hundreds.banding
    INNER JOIN my.my_DEP my_DEP
    ON 5MillTbl.organization_ID = my_DEP.organization_ID
    INNER JOIN my.my_40millTbl
    ON 5MillTbl.seqID = my_40millTbl.seqID
    LEFT OUTER JOIN my.hundredRowsTbl hundredRowsTbl
    ON my_DEP.addr_id = hundredRowsTbl.ID2
    LEFT OUTER JOIN my.30millTbl 30millTbl
    ON my_DEP.organization_ID = 30millTbl.dept_id
    WHERE 1=1
    AND 5MillTbl.ID IS NOT NULL
    AND ( 5MillTbl.checkout_TIME >= TO_DATE ('01-01-2009 00:00:00', 'DD-MM-YYYY HH24:MI:SS')
    AND 5MillTbl.checkout_TIME <TO_DATE ('12-31-2010 00:00:00', 'DD-MM-YYYY HH24:MI:SS')
    AND ( 5MillTbl.col2 IS NULL
    OR NOT (5MillTbl.col2 = 5
    OR 5MillTbl.col2 = 6)
    AND 5MillTbl.ID IS NOT NULL
    AND 30millTbl.TYPE= '30'
    AND my_DEP.addr_id = 61

  • I need a help on Join please or anybody help to rewrite the query

    select
    x.QUEST_DESC,y.QUES_RESPONSE, y.user_id from
    (select c.QUES_CODE, c.QUEST_DESC, null user_id from CLINICAL_HISTORY_QUESTIONS c where c.CLINICAL_TYPE_CODE=2) x,
    (select a.QUEST_CODE, a.QUEST_RESPONSE, a.user_id from PATIENT_CLINICAL_HISTORIES a where a.CLINICAL_TYPE_CODE=2 and a.user_ID=88) y
    where x.QUEST_CODE =y.QUEST_CODE(+)
    Is there any way I can display same user_ID 88 on the null USER_ID (Joined one)
    my result is
    QUEST_DESC     QUEST_RESPONSE     USER_ID
    Fibrostenotic               U     88
    Inflammatory               U     88
    Int Penetrating/Perforating          U     88
    Perianal Perforating Disease          U     88
    Uc Like                    U     88
    Iv Therapy          
    Fistula          
    Bleeding          
    Osteopenia          
    Sibo          
    Urgency          
    Extraintestinal Sx          
    Steroid Dependent          
    Immunosuppressive Tx          
    Fever/Chills          
    Obstructive Sx          
    Stool Consistency          
    Adb Pain          
    Other          
    Growth          
    Osteoporosis          
    Stool Frequency          
    Flare Of Disease
    Edited by: Paul Vellackel on Jul 2, 2010 3:20 PM
    Edited by: Paul Vellackel on Jul 2, 2010 3:55 PM

    sigh
    What we were asking you is to post data we can work with rightaway, so CREATE TABLE statement, and INSERT INTO statement. So: not output, but statements...
    Since I'm in a good mood (we're in the semi finals ;) ), here's an example of how you should post your data:
    create table a1 as
    select 1 quest_code, 'Fibrostenotic' quest_desc from dual union
    select 2, 'Inflammatory' from dual union
    select 3, 'Int Penetrating/Perforating' from dual union
    select 4, 'Perianal Perforating Disease' from dual union
    select 5, 'Uc Like' from dual union
    select 6, 'Flare Of Disease' from dual union
    select 7, 'Immunosuppressive Tx' from dual union
    select 8, 'Iv Therapy' from dual union
    select 9, 'Stool Consistency' from dual union
    select 10, 'Urgency' from dual union
    select 11, 'Stool Frequency' from dual union
    select 12, 'Bleeding' from dual union
    select 13, 'Adb Pain' from dual union
    select 14, 'Fever/Chills' from dual union
    select 15, 'Fistula' from dual union
    select 16, 'Obstructive Sx' from dual union
    select 17, 'Extraintestinal Sx' from dual union
    select 18, 'Steroid Dependent' from dual union
    select 19, 'Sibo' from dual union
    select 20, 'Osteoporosis' from dual union
    select 21, 'Osteopenia' from dual union
    select 22, 'Growth' from dual union
    select 23,  'Other' from dual;
    create table a2 as
    select 1 quest_code, 'U' quest_response, 88 user_id from dual union
    select 2, 'U', 88 from dual union
    select 3, 'U', 88 from dual union
    select 4, 'U', 88 from dual union
    select 5, 'U', 88 from dual;
    create table a3 as
    select 'testuserb' user_name, 88 user_id from dual;Posted like that, we can copy+paste and try to help you rightaway instead of waisting time formatting, putting quotes right etc. etc.
    Also use the {noformat}{noformat} tag when you post an example.
    That way it will stay formatted and indented.
    So, when you type: {noformat}select *
    from dual;{noformat}
    it will appear as: select *
    from dual;when you post it.
    Finally, perhaps you could try something like this:SQL> select a1.quest_desc
    2 , a2.quest_response
    3 , case
    4 when (select a3.user_id
    5 from a3
    6 where a3.user_id = a2.user_id) is not null
    7 then (select a3.user_id
    8 from a3
    9 where a3.user_id = a2.user_id)
    10 else (select a3.user_id
    11 from a3
    12 where a3.user_name = 'testuserb')
    13 end user_id
    14 from a1
    15 , a2
    16 where a1.quest_code = a2.quest_code(+);
    QUEST_DESC Q USER_ID
    Fibrostenotic U 88
    Inflammatory U 88
    Int Penetrating/Perforating U 88
    Perianal Perforating Disease U 88
    Uc Like U 88
    Iv Therapy 88
    Fistula 88
    Bleeding 88
    Osteopenia 88
    Sibo 88
    Urgency 88
    Extraintestinal Sx 88
    Steroid Dependent 88
    Immunosuppressive Tx 88
    Fever/Chills 88
    Obstructive Sx 88
    Stool Consistency 88
    Adb Pain 88
    Other 88
    Growth 88
    Osteoporosis 88
    Stool Frequency 88
    Flare Of Disease 88
    23 rows selected.

  • Need sql query to find out Joins attached with folders in Discoverer

    Hi,
    Can anyone let me know the sql query which can be used to identify the joins which are attached to the folders.
    Actually we have to identify all the joins conditions from folders those are migrated from one instance to others.
    Thanks
    abhishek

    I recommend that you implement the admin EUL supplied by oracle, you can get there a lot of repository information (metalink note: 556932.1).
    Try to use this (maybe you will need some pkg's):
    SELECT
    DECODE(KEYS.FK_MANDATORY,
    1,
    'Always exist in master folder',
    'Might not exist in master folder') "Detail Item values",
    EUL10G_US.EUL5_GET_JOIN(EXP.EXP_ID, 'N') "Join Master --> Detail",
    KEYS.KEY_DESCRIPTION JOIN_DESCRIPTION,
    KEYS.KEY_DEVELOPER_KEY JOIN_IDENTIFIER,
    KEYS.KEY_NAME JOIN_NAME,
    DECODE(SUBSTR(KEYS.KEY_NAME, 1, 19),
    'AUTO_GENERATED_NAME',
    'Yes',
    'No') "AutoGen",
    DECODE(DECODE(SUBSTR(KEYS.KEY_NAME, 1, 19),
    'AUTO_GENERATED_NAME',
    'Yes',
    'No') ,
    'Yes',
    EUL10G_US.EUL5_GET_JOIN(EXP.EXP_ID),
    KEYS.KEY_NAME) "Actual Join Name",
    KEYS.KEY_UPDATED_DATE JOIN_LAST_UPDATE,
    DECODE(KEYS.FK_ONE_TO_ONE, 1, 'One to one join', NULL) "One to One join",
    DECODE(KEYS.FK_MSTR_NO_DETAIL,
    1,
    'Outer join on detail' || CHR(10),
    NULL) "Outer Join on Detail",
    DECODE(KEYS.FK_DTL_NO_MASTER,
    1,
    'Outer join on master' || CHR(10),
    NULL) "Outer Join on Master",
    DECODE(KEYS.FK_MSTR_NO_DETAIL,
    1,
    'Outer join on detail' || CHR(10),
    NULL) || DECODE(KEYS.FK_DTL_NO_MASTER,
    1,
    'Outer join on master' || CHR(10),
    NULL) ||
    DECODE(KEYS.FK_ONE_TO_ONE, 1, 'One to one join', NULL) "Optional Join Configurations",
    OBJ.OBJ_NAME "MASTER_FOLDER",
    OBJ_DETAIL.OBJ_NAME "DETAIL_FOLDER"
    FROM EUL10G_US.EUL5_OBJS OBJ,
    EUL10G_US.EUL5_EXPRESSIONS EXP,
    EUL10G_US.EUL5_KEY_CONS KEYS,
    EUL10G_US.EUL5_OBJS OBJ_DETAIL
    WHERE ((KEYS.KEY_ID = EXP.JP_KEY_ID) AND
    (OBJ.OBJ_ID = KEYS.FK_OBJ_ID_REMOTE) AND
    (OBJ_DETAIL.OBJ_ID = keys.KEY_OBJ_ID));

  • Outer join on query with OR clause

    hi all, i am having problem outerjoining a query with or clause
    here is my data
    WITH table1 AS
    SELECT  'test' txt1, 'pak' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL
    SELECT  null txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL
    SELECT  null txt1, NULL txt2, 'ced3' txt3, 'su3' txt4 FROM dual UNION ALL
    SELECT  null txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL
    SELECT  'text5' txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL
    SELECT  null txt1, NULL txt2, null txt3, null txt4 FROM dual
    ,table2 AS
    SELECT 111 pid, 'test' txt1, 'pak4' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL
    SELECT 222 pid, 'test1' txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL
    SELECT 333 pid, 'test2' txt1, 'pak3' txt2, 'ced3' txt3, 'su4' txt4 FROM dual UNION ALL
      SELECT 444 pid, 'test2' txt1, 'pak3' txt2, 'ced4' txt3, 'su3' txt4 FROM dual
    SELECT b.pid, a.*
    from table1 a, table2 b
    WHERE (a.txt1 = b.txt1 OR
           a.txt1 IS NULL AND a.txt2=b.txt2 OR
           Nvl(a.txt2, a.txt1) IS NULL AND a.txt3 = b.txt3 OR
           Nvl(a.txt2, a.txt1) IS NULL  AND a.txt3 IS NULL AND a.txt4 = b.txt4
           ) as you can see i am joining table1 and table 2. i am joining with txt1, if txt1 is null then join by txt2, if null then join by txt3 and so on.
    the code above product this output
    PID     TXT1     TXT2     TXT3     TXT4
    ===     ====     ===   ==== ====
    111     test     pak      ced     su
    222             pak      ced2     su2
    333                     ced3     su3
    444                          su3this output is partially correct. only 4 rows were display and two was left out
    SELECT  'text5' txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL
    SELECT  null txt1, NULL txt2, null txt3, null txt4 FROM dual i tried using outer join but oracle complain that i cannot use outerjoin with OR clause.
    can someone help modify my query to display the output below ?
    PID     TXT1     TXT2     TXT3     TXT4
    ===    ====      ===   ====  ====
    111     test     pak      ced     su
    222             pak      ced2     su2
    333                     ced3     su3
    444                          su3
    NULL  NULL   NULL    NULL   NULL
         test5

    Not sure you can do it with the Oracle style outer joins, but wioth ANSI style joins it is simple, actually exactly as you had it.
    SQL> set null null;
    SQL> WITH table1 AS (
      2   SELECT  'test' txt1, 'pak' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL
      3   SELECT  null txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL
      4   SELECT  null txt1, NULL txt2, 'ced3' txt3, 'su3' txt4 FROM dual UNION ALL
      5   SELECT  null txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL
      6   SELECT  'text5' txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL
      7   SELECT  null txt1, NULL txt2, null txt3, null txt4 FROM dual),
      8  table2 AS (
      9   SELECT 111 pid, 'test' txt1, 'pak4' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL
    10   SELECT 222 pid, 'test1' txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL
    11   SELECT 333 pid, 'test2' txt1, 'pak3' txt2, 'ced3' txt3, 'su4' txt4 FROM dual UNION ALL
    12   SELECT 444 pid, 'test2' txt1, 'pak3' txt2, 'ced4' txt3, 'su3' txt4 FROM dual)
    13  SELECT b.pid, a.*
    14  from table1 a
    15     LEFT JOIN table2 b
    16        ON (a.txt1 = b.txt1 OR
    17            a.txt1 IS NULL AND a.txt2=b.txt2 OR
    18            Nvl(a.txt2, a.txt1) IS NULL AND a.txt3 = b.txt3 OR
    19            Nvl(a.txt2, a.txt1) IS NULL  AND a.txt3 IS NULL AND a.txt4 = b.txt4);
           PID TXT1   TXT2   TXT3   TXT4
           111 test   pak    ced    su
           222 null   pak    ced2   su2
           333 null   null   ced3   su3
           444 null   null   null   su3
    null       text5  null   null   su3
    null       null   null   null   nullJohn

  • Left join problem

    hi guys,
    please see this query once.
    in 3rd left join i am getting error like subqueries not allowed here.
    can you help me to reslove this.
    SELECT
    '20060201'||d.acct_num as user_ref_area,
    ind.name_first||' ' ||ind.name_last AS full_name,
    PA.ADDR_FIRST_LINE,
    PA.CITY_NAME||','||
    PA.STATE_ABBR as city_state,
    PA.ZIP_CDE AS zip_cde,
    CASE WHEN iphr.pho_stat_cde ='G' THEN
    '000'||pha.pho_exchg_num||pha.pho_line_num
    ELSE '0000000000'
    END AS home_phone,
    ind.ss_num,
    d.activity_date,
    d.acct_num
    FROM (
    select j.acct_num,j.activity_date
    from (
    select dxr.acct_num,
    to_char(o3.o3bfct) as activity_date
    from debtp.o3
    JOIN debtp.acct_xref dxr
    ON o3.o3e5cd = dxr.e5cd
    WHERE o3dhce in ('aj','ja','ta')
    AND load_dt >=to_date('2006/01/28','yyyy/mm/dd')-- trunc(sysdate-4) --NEED TO USE SYSDATE-4                                        
    UNION
    select account_number,TO_CHAR(data_date, 'YYYYMMDD') as activitydate
    from clctdm.triad_history
    where data_date =to_date('2006/01/31','yyyy/mm/dd')--trunc(sysdate-1) --NEED TO USE SYSDATE-1
    and delq_coll_ind in ('960','961','962','963')
    ) j
    left join
    select ACCT_NUM
    from hbivt1.pp_fd_accts FDAI
    where FDAI.DATE_activity >='20060102'--to_char(trunc(add_months(sysdate,-1)),'yyyymmdd')
    ) k
    on j.acct_num =k.acct_num
    where k.acct_num IS null
    ) d
    JOIN AUTOR3.ACCT_XREF XR --lookup for arr_id_acct values
    ON d.acct_num =xr.acct_num
    JOIN AUTOR3.ARR_IP_POSTL_REL AIPL --lookup for postl_addr_id
    ON AIPL.ARR_ID = XR.ARR_ID_ACCT
    and aipl.actv_ind ='0'
    join autor3s.indv ind --table with values for FIRSTDATA
    on aipl.hi_num =ind.hi_num_indv
    Left JOIN AUTOR3s.POSTL_ADDR PA ----table with values for FIRSTDATA
    ON aipl.POSTL_ADDR_ID = PA.POSTL_ADDR_ID
    left join autor3.ip_pho_rel iphr
    on iphr.hi_num =aipl.hi_num and
    start_dt_tm =(
    select max(iphr2.start_dt_tm) as start_dt_tm from AUTOR3.IP_PHO_REL IPHR2
    WHERE iphr2.rank_num='1'
    and iphr2.ip_pho_rel_cde='001000'
    and iphr2.actv_ind='0'
    and iphr2.hi_num =aipl.hi_num
    )

    Oracle only supports outer joins as extended equalities.
    You'll have to use the syntax:
    FROM PC2KAUDIT,AUDITDETAIL
    WHERE
    ... (other where clause)
    AND
    PC2KAUDIT.AUDITID = AUDITDETAIL.AUDITID (+)
    This will do basically the same thing. Unfortunately there is no common syntax, unless oyu have a fancy ODBC driver, which might do this translation for you.
    null

  • Joins And For all Enteries in Select Statement

    Could you please tell me when there is a high amount of data which is being handled in the table, does the use of INNER JOINS and FOR ALL ENTERIES in SELECT Statement decreases the system performance? ?
    Can you also let me know where can i get some tips regarding do's and dont's for ABAP Programming, I want to increase my system performance.
    Currently the programs which are being used are taking a lot of time for execution...
    Its very URGENT!

    Hai Jyotsna
    Go through the following Tips for improving Performence
    For all entries
    The for all entries creates a where clause, where all the entries in the driver table are combined with OR. If the number of entries in the driver table is larger than rsdb/max_blocking_factor, several similar SQL statements are executed to limit the length of the WHERE clause.
    The plus
    Large amount of data
    Mixing processing and reading of data
    Fast internal reprocessing of data
    Fast
    The Minus
    Difficult to program/understand
    Memory could be critical (use FREE or PACKAGE size)
    Some steps that might make FOR ALL ENTRIES more efficient:
    Removing duplicates from the driver table
    Sorting the driver table
    If possible, convert the data in the driver table to ranges so a BETWEEN statement is used instead of and OR statement:
                   FOR ALL ENTRIES IN i_tab
                      WHERE mykey >= i_tab-low and
                 mykey <= i_tab-high.
    Nested selects
    The plus:
    Small amount of data
    Mixing processing and reading of data
    Easy to code - and understand
    The minus:
    Large amount of data
    when mixed processing isn’t needed
    Performance killer no. 1
    Select using JOINS
    The plus
    Very large amount of data
    Similar to Nested selects - when the accesses are planned by the programmer
    In some cases the fastest
    Not so memory critical
    The minus
    Very difficult to program/understand
    Mixing processing and reading of data not possible
    Use the selection criteria
    SELECT * FROM SBOOK.                   
      CHECK: SBOOK-CARRID = 'LH' AND       
                      SBOOK-CONNID = '0400'.        
    ENDSELECT.                             
    SELECT * FROM SBOOK                     
      WHERE CARRID = 'LH' AND               
            CONNID = '0400'.                
    ENDSELECT.                              
    Use the aggregated functions
    C4A = '000'.              
    SELECT * FROM T100        
      WHERE SPRSL = 'D' AND   
            ARBGB = '00'.     
      CHECK: T100-MSGNR > C4A.
      C4A = T100-MSGNR.       
    ENDSELECT.                
    SELECT MAX( MSGNR ) FROM T100 INTO C4A 
    WHERE SPRSL = 'D' AND                
           ARBGB = '00'.                  
    Select with view
    SELECT * FROM DD01L                    
      WHERE DOMNAME LIKE 'CHAR%'           
            AND AS4LOCAL = 'A'.            
      SELECT SINGLE * FROM DD01T           
        WHERE   DOMNAME    = DD01L-DOMNAME 
            AND AS4LOCAL   = 'A'           
            AND AS4VERS    = DD01L-AS4VERS 
            AND DDLANGUAGE = SY-LANGU.     
    ENDSELECT.                             
    SELECT * FROM DD01V                    
    WHERE DOMNAME LIKE 'CHAR%'           
           AND DDLANGUAGE = SY-LANGU.     
    ENDSELECT.                             
    Select with index support
    SELECT * FROM T100            
    WHERE     ARBGB = '00'      
           AND MSGNR = '999'.    
    ENDSELECT.                    
    SELECT * FROM T002.             
      SELECT * FROM T100            
        WHERE     SPRSL = T002-SPRAS
              AND ARBGB = '00'      
              AND MSGNR = '999'.    
      ENDSELECT.                    
    ENDSELECT.                      
    Select … Into table
    REFRESH X006.                 
    SELECT * FROM T006 INTO X006. 
      APPEND X006.                
    ENDSELECT
    SELECT * FROM T006 INTO TABLE X006.
    Select with selection list
    SELECT * FROM DD01L              
      WHERE DOMNAME LIKE 'CHAR%'     
            AND AS4LOCAL = 'A'.      
    ENDSELECT
    SELECT DOMNAME FROM DD01L    
    INTO DD01L-DOMNAME         
    WHERE DOMNAME LIKE 'CHAR%' 
           AND AS4LOCAL = 'A'.  
    ENDSELECT
    Key access to multiple lines
    LOOP AT TAB.          
    CHECK TAB-K = KVAL. 
    ENDLOOP.              
    LOOP AT TAB WHERE K = KVAL.     
    ENDLOOP.                        
    Copying internal tables
    REFRESH TAB_DEST.              
    LOOP AT TAB_SRC INTO TAB_DEST. 
      APPEND TAB_DEST.             
    ENDLOOP.                       
    TAB_DEST[] = TAB_SRC[].
    Modifying a set of lines
    LOOP AT TAB.             
      IF TAB-FLAG IS INITIAL.
        TAB-FLAG = 'X'.      
      ENDIF.                 
      MODIFY TAB.            
    ENDLOOP.                 
    TAB-FLAG = 'X'.                  
    MODIFY TAB TRANSPORTING FLAG     
               WHERE FLAG IS INITIAL.
    Deleting a sequence of lines
    DO 101 TIMES.               
      DELETE TAB_DEST INDEX 450.
    ENDDO.                      
    DELETE TAB_DEST FROM 450 TO 550.
    Linear search vs. binary
    READ TABLE TAB WITH KEY K = 'X'.
    READ TABLE TAB WITH KEY K = 'X' BINARY SEARCH.
    Comparison of internal tables
    DESCRIBE TABLE: TAB1 LINES L1,      
                    TAB2 LINES L2.      
    IF L1 <> L2.                        
      TAB_DIFFERENT = 'X'.              
    ELSE.                               
      TAB_DIFFERENT = SPACE.            
    LOOP
    AT TAB1.                     
        READ TABLE TAB2 INDEX SY-TABIX. 
        IF TAB1 <> TAB2.                
          TAB_DIFFERENT = 'X'. EXIT.    
        ENDIF.                          
      ENDLOOP.                          
    ENDIF.                              
    IF TAB_DIFFERENT = SPACE.           
    ENDIF.                              
    IF TAB1[] = TAB2[].  
    ENDIF.               
    Modify selected components
    LOOP AT TAB.           
    TAB-DATE = SY-DATUM. 
    MODIFY TAB.          
    ENDLOOP.               
    WA-DATE = SY-DATUM.                    
    LOOP AT TAB.                           
    MODIFY TAB FROM WA TRANSPORTING DATE.
    ENDLOOP.                               
    Appending two internal tables
    LOOP AT TAB_SRC.              
      APPEND TAB_SRC TO TAB_DEST. 
    ENDLOOP
    APPEND LINES OF TAB_SRC TO TAB_DEST.
    Deleting a set of lines
    LOOP AT TAB_DEST WHERE K = KVAL. 
      DELETE TAB_DEST.               
    ENDLOOP
    DELETE TAB_DEST WHERE K = KVAL.
    Tools available in SAP to pin-point a performance problem
    ·                The runtime analysis (SE30)
    ·                SQL Trace (ST05)
    ·                Tips and Tricks tool
    ·                The performance database
    Optimizing the load of the database
    Using table buffering
    Using buffered tables improves the performance considerably. Note that in some cases a statement can not be used with a buffered table, so when using these statements the buffer will be bypassed. These statements are:
    Select DISTINCT
    ORDER BY / GROUP BY / HAVING clause
    Any WHERE clause that contains a sub query or IS NULL expression
    JOIN s
    A SELECT... FOR UPDATE
    If you wan t to explicitly bypass the buffer, use the BYPASS BUFFER addition to the SELECT clause.
    Use the ABAP SORT Clause Instead of ORDER BY
    The ORDER BY clause is executed on the database server while the ABAP SORT statement is executed on the application server. The database server will usually be the bottleneck, so sometimes it is better to move the sort from the database server to the application server.
    If you are not sorting by the primary key ( E.g. using the ORDER BY PRIMARY key statement) but are sorting by another key, it could be better to use the ABAP SORT statement to sort the data in an internal table. Note however that for very large result sets it might not be a feasible solution and you would want to let the database server sort it.
    Avoid the SELECT DISTINCT Statement
    As with the ORDER BY clause it could be better to avoid using SELECT DISTINCT, if some of the fields are not part of an index. Instead use ABAP SORT + DELETE ADJACENT DUPLICATES on an internal table, to delete duplicate rows.
    Thanks & regards
    Sreenivasulu P

  • Nested Left Outer Join : Data Set

    Hi All
    I am bit confused about data set used by Nested Left outer join.
    Can anyone help me.
    Here is sample data:
    Tables (Name, 3 Column each, total rows and matched rows if any):
         Table 1          
         A     B     C
         Total 20 Rows          
         Table 2          
         A     D     E
         Total 50 Rows and 10 Matching on      2.A = 1.A     
         Table 3          
         D     M     N
         Total 15 Rows and 15 Matching on 3.D = 2.D     
         Table 4          
         M     X     Y
         Total 20 Rows and 10 Matching on 4.M = 3.M     
    Sql
    select *
    From Table 1
    Left Outer Join on Table 2 on
                   2.A = 1.A
    -- Data set 1 will contain 20 Rows (10 matching and 10 non matching)
    Left Outer Join on Table 3 on
                   3.D = 2.D
    -- What will be data set? 20 Rows of Data set 1 or 15 Matching Rows?
    Left Outer Join on Table 4 on
                   4.M = 3.M
    -- What will be data set? X Rows of Data set 2 or 10 Matching Rows?
    Please have a look and clear my understanding.

    SeshuGiri wrote:
    I have two tables defined (below). Emp table has data and there is no data in Emp_Type table yet! Right now it is empty.
    I want to write a query that returns data from both the tables even though there is no data in Emp_type table. I am using left outer join but it returning nothing. Anyone can help?
    select *
    from emp e
    left outer join emp_Type t
    on e.empid = t.empid
    WHERE t.type_id = 1
    and t.end_date is null;
    The join is including all rows from emp, just like you want.
    The WHERE clause is discarding all of those rows. Since all the columns from emp_type (alias t) are NULL, the condition "t.type_id = 1" in the WHERE clause is never true.
    Perhaps you meant to include all those conditions in the join conditions, like this:
    select *
      from emp e
      left outer join emp_Type t
        on e.empid = t.empid
       and t.type_id = 1
       and t.end_date is null;Edited by: Frank Kulash on Jan 30, 2012 3:56 PM

  • Joining two tablew

    WITH table1 AS
      SELECT 123 prodid, 111 cid, 'BBB' bid, '563C' fid FROM dual UNION ALL
      SELECT 234 prodid, 222 cid, 'cccc' bid, '663C' fid FROM dual UNION ALL
      SELECT 567 prodid, 22 cid, 'ddd' bid, '763C' fid FROM dual
    table2 AS
    SELECT NULL cid, 'BBB' bid, NULL fid FROM dual UNION ALL
    SELECT 222 cid,  'ccc' bid, '663C' did FROM dual UNION all
    SELECT NULL cid, null bid, '563C' fid FROM dual UNION all
    SELECT 22 cid, 'BBB' bid, NULL FROM dual
    )what i want to do is to join table2 to table1 on the following logic
    -- look at cid, if cid is not null then join with cid to table1
    -- if cid is null then look at bid and see if it has value. if it does then join wit table2 bid to table1 bid
    -- if bid is null, then look at fid and join the two table on fid
    so the output should be something like this
    prodid    cid      bid    fid
    =======  =====     =====   =====
    123      null      BBB     NULL
    234      222       ccc     663c
    123      null      NULL    563c
    567      22        BBB     null
    can someone help write a query that will join table2 to table1 and product the above output ?
    thanks

    Hi,
    elmasduro wrote:
    thanks for the reply but is there a cleaner/easier way than doing the decode in where clause.
    i am afraid this can hurt performance as table grows.
    if you know a simpler way without using too many decode , please let me know. thanksI'm not sure why you think DECODE won't scale. When you talk about "as table grows", do you mean that you will be adding more and more id columns? If so, then you might find CASE to be cleaner and easier:
    SELECT     t1.prodid, t2.cid, t2.bid, t2.fid
    FROM     table1     t1
    JOIN     table2     t2     ON     CASE
                             WHEN  t2.cid     = t1.cid     THEN  'YES'
                             WHEN  t2.cid     IS NOT NULL     THEN  'NO'
                             WHEN  t2.bid     = t1.bid     THEN  'YES'
                             WHEN  t2.bid     IS NOT NULL     THEN  'NO'
                             WHEN  t2.fid     = t1.fid     THEN  'YES'
                        END = 'YES'
    ;Dimak showed how to do the job without any DECODE (or CASE). However, UNION is inefficient, and not necessary in this case:
    SELECT     t1.prodid, t2.cid, t2.bid, t2.fid
    FROM     table1     t1
    JOIN     table2     t2     ON     t1.cid     = t2.cid
                   OR     (     t2.cid     IS NULL
                        AND     t1.bid     = t2.bid
                   OR     (     NVL (t2.bid, t2.cid)     IS NULL
                        AND     t1.fid               = t2.fid
    ;

  • Getting a black image after joining two images

    Hey Guys,
    I have joined two images. In the joined image. i am getting the first image but the second one im getting as a black image. Can you please tell me what is the problem??
    Below is the code:
    w = inv*img[inv].getWidth(null) + img1.getWidth(null);
         h = Math.max(img[inv].getHeight(null), img1.getHeight(null));
         BufferedImage[] joinedImg = new BufferedImage[lnuInvoiceIndex];
         Graphics2D[] g = new Graphics2D[lnuInvoiceIndex];
    JPEGImageEncoder[] encoder=new JPEGImageEncoder[lnuInvoiceIndex];
         for(int join=0;join<=lnuInvoiceIndex;join++){
    joinedImg[join]=new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    g[join] = joinedImg[join].createGraphics();
    g[join].drawImage((BufferedImage)thumbImage[inv], 0,0, null);
    encoder[join] = JPEGCodec.createJPEGEncoder(response.getOutputStream());
    encoder[join].encode((BufferedImage)joinedImg[join]);
    }

    import java.awt.*;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import javax.swing.*;
    public class JoinImages {
        private JPanel getContent(BufferedImage[] images) {
            JPanel panel = new JPanel(new BorderLayout());
            panel.add(wrap(join(images, 4)), "Before");
            panel.add(wrap(join(images, 1)), "Last");
            panel.add(wrap(join(images, 2)));
            return panel;
        private BufferedImage join(BufferedImage[] images, int rows) {
            int cols = images.length/rows;
            // For all images having the same size.
            int iw = images[0].getWidth();
            int ih = images[0].getHeight();
            int w = cols*iw;
            int h = rows*ih;
            int type = BufferedImage.TYPE_INT_RGB;
            BufferedImage image = new BufferedImage(w, h, type);
            Graphics2D g2 = image.createGraphics();
            for(int j = 0, index = 0; j < rows; j++) {
                for(int k = 0; k < cols; k++) {
                    int x = k*iw;
                    int y = j*ih;
                    g2.drawImage(images[index++], x, y, null);
            g2.dispose();
            return image;
        private JLabel wrap(BufferedImage image) {
            return new JLabel(new ImageIcon(image),
                              JLabel.CENTER);
        public static void main(String[] args) throws IOException {
            String[] ids = { "-c---", "--g--", "---h-", "----t" };
            BufferedImage[] images = new BufferedImage[ids.length];
            for(int j = 0; j < images.length; j++) {
                String path = "images/geek/geek" + ids[j] + ".gif";
                images[j] = javax.imageio.ImageIO.read(new File(path));
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.add(new JoinImages().getContent(images));
            f.pack();
            f.setLocation(200,200);
            f.setVisible(true);
    }Geek images from [Using Swing Components: Examples|http://java.sun.com/docs/books/tutorial/uiswing/examples/components/index.html].

  • Help me to tune this pl/sql code...

    This code takes almost 3 minutes to execute....can you help where to improve?
    BEGIN                              
         DECLARE
             v_CntTextIdNotProcessed  NUMBER:=0;
                    BEGIN               
                       SELECT COUNT(1) INTO v_CntTextIdNotProcessed FROM COB_T_LT_TEXTID_SO_RECOMPILE WHERE IsProcessed = 0;
                       IF (v_CntTextIdNotProcessed > 0) THEN
                       BEGIN
                               INSERT INTO COB_T_LANG_TRANS_OPERATION
                                    OPERATIONID,
                                    OPERATIONCODE,
                                    OPERATIONREVISION,
                                    ISPROCESSED,                      
                                    CREATEDON,    
                                    CREATEDBY         
                            SELECT DISTINCT
                                    Id,
                                    OperationCode,
                                    OperationRevision,
                                    0,
                                    cob_f_getutc,
                                    'COB_WP_INS_LANG_TRANS_SO'                   
                            From
                                SELECT  Op.Id,Op.OperationCode,Op.OperationRevision
                                  FROM Function_ Fn
                                          INNER JOIN Function_Message Ft
                                              ON Ft.Functionid = Fn.Id
                                              AND Ft.Active    =1
                                              AND Fn.Active    =1
                                          INNER JOIN Text_Translation TT
                                              ON TT.Textid      = Ft.Textid
                                              AND TT.Active     =1
                                              AND (TT.Short    <> 'Null'
                                              OR TT.Medium     <> 'Null'
                                              OR TT.Extended   <> 'Null')
                                          INNER JOIN Function_Type Fnty
                                              ON Fn.Functiontype=Fnty.Functiontype
                                              AND Fnty.Active   =1
                                          INNER JOIN Operation_Step_Function Osf
                                              ON (Osf.Functionid=Fn.Id)
                                              AND Osf.Active    =1
                                          INNER JOIN Operation_Step Os
                                              ON Os.Id     =Osf.Operationstepid
                                              AND Os.Active=1
                                          INNER JOIN Operation Op
                                              ON Op.Id  = Os.Operationid
                                     -- AND op.defaultoperationrevision = 1
                                              AND Op.Active =1
                                              And Op.Revisionstatusid In (1,4)
                                              AND TO_CHAR(Op.Id) IN (SELECT DISTINCT TO_CHAR(SUBSTR(FPV.PropertyValue,INSTR(FPV.PropertyValue, '<PropertyBagItem Key="OperationID"><Value xsi:type="xsd:int">')+61,9))
                                                                FROM
                                                                       OPERATION OP
                                                                       INNER JOIN OPERATION_STEP OS ON Op.Id = OS.OperationId
                                                                       INNER JOIN OPERATION_STEP_FUNCTION OSF ON OS.Id = OSF.OperationStepId
                                                                       INNER JOIN   FUNCTION_ F ON OSF.FunctionId = F.id
                                                                       AND F.FunctionType = 21
                                                                       INNER JOIN FUNCTION_PROPERTY_VALUE FPV ON FPV.Functionid = F.Id  
                                                                WHERE UPPER(OP.OperationRevision) = 'WRAPPER')                                                                                                                       
                                  WHERE TT.TextID IN  (SELECT TextId FROM COB_T_LT_TEXTID_SO_RECOMPILE WHERE IsProcessed = 0)                                                               
                                  UNION                 
                                  SELECT Op.Id,Op.OperationCode,Op.OperationRevision
                                  FROM Function_Output Fo
                                      INNER JOIN Function_Output_Routing Forout
                                          ON Forout.Functionoutputid = Fo.Id
                                          INNER JOIN Text_Translation TT
                                          ON TT.Textid      = Forout.PromptTextid
                                          AND (TT.Short    <> 'Null'
                                          OR TT.Medium     <> 'Null'
                                          OR TT.Extended   <> 'Null')
                                      INNER JOIN Function_Output_Routing_Type Fort
                                          ON Fort.Id=Forout.Outputroutingtypeid
                                      INNER JOIN Text_Translation Ttdt
                                          ON Ttdt.Textid           = Fort.Textid
                                          AND Ttdt.Languageid      =1033
                                          AND Upper(Ttdt.Extended) = 'USER'
                                          INNER JOIN Function_ Fn
                                          ON Fn.Id = Fo.Functionid
                                      INNER JOIN Function_Type Fnty
                                          ON Fn.Functiontype=Fnty.Functiontype
                                      INNER JOIN Operation_Step_Function Osf
                                          ON (Osf.Functionid=Fn.Id)
                                      INNER JOIN Operation_Step Os
                                        ON Os.Id=Osf.Operationstepid
                                      INNER JOIN Operation Op
                                          ON Op.Id  = Os.Operationid
                                          And Op.Revisionstatusid In (1,4)
                                         AND to_char(Op.Id) IN (SELECT DISTINCT TO_CHAR(SUBSTR(FPV.PropertyValue,INSTR(FPV.PropertyValue, '<PropertyBagItem Key="OperationID"><Value xsi:type="xsd:int">')+61,9))
                                                                FROM
                                                                       OPERATION OP
                                                                       INNER JOIN OPERATION_STEP OS ON Op.Id = OS.OperationId
                                                                       INNER JOIN OPERATION_STEP_FUNCTION OSF ON OS.Id = OSF.OperationStepId
                                                                       INNER JOIN   FUNCTION_ F ON OSF.FunctionId = F.id
                                                                       AND F.FunctionType = 21
                                                                       INNER JOIN FUNCTION_PROPERTY_VALUE FPV ON FPV.Functionid = F.Id  
                                                                WHERE UPPER(OP.OperationRevision) = 'WRAPPER')
                                  WHERE  TT.TextID IN  (SELECT TextId FROM COB_T_LT_TEXTID_SO_RECOMPILE WHERE IsProcessed = 0)                                                                                                              
                                  UNION                 
                                SELECT Op.Id,Op.OperationCode,Op.OperationRevision
                                  FROM Function_Input Fi
                                      INNER JOIN Text_Translation TT
                                          ON ( TT.Textid    = Fi.Prompttextid
                                          AND TT.Active     =1)
                                          AND (TT.Short    <> 'Null'
                                          OR TT.Medium     <> 'Null'
                                          OR TT.Extended   <> 'Null')
                                      INNER JOIN Function_Input_Source_Type Fist
                                          ON Fist.Id     = Fi.Inputsourcetypeid
                                          AND Fist.Active=1
                                      INNER JOIN Text_Translation Ttdt
                                          ON Ttdt.Textid           = Fist.Textid
                                          AND Ttdt.Active          =1
                                          AND Ttdt.Languageid      = 1033
                                          AND Upper(Ttdt.Extended) = 'USER'
                                      INNER JOIN Function_ Fn
                                          ON Fn.Id     = Fi.Functionid
                                          AND Fn.Active=1
                                      INNER JOIN Function_Type Fnty
                                          ON Fn.Functiontype=Fnty.Functiontype
                                          AND Fnty.Active   =1
                                      INNER JOIN Operation_Step_Function Osf
                                          ON Osf.Functionid=Fn.Id
                                          AND Osf.Active   =1
                                      INNER JOIN Operation_Step Os
                                          ON Os.Id = Osf.Operationstepid
                                          AND Os.Active=1
                                      INNER JOIN Operation Op
                                         ON Op.Id = Os.Operationid
                                        AND Op.Active                =1
                                        And Op.Revisionstatusid In (1,4)
                                        AND TO_CHAR(Op.Id) IN (SELECT DISTINCT TO_CHAR(SUBSTR(FPV.PropertyValue,INSTR(FPV.PropertyValue, '<PropertyBagItem Key="OperationID"><Value xsi:type="xsd:int">')+61,9))
                                                                FROM
                                                                       OPERATION OP
                                                                       INNER JOIN OPERATION_STEP OS ON Op.Id = OS.OperationId
                                                                       INNER JOIN OPERATION_STEP_FUNCTION OSF ON OS.Id = OSF.OperationStepId
                                                                       INNER JOIN   FUNCTION_ F ON OSF.FunctionId = F.id
                                                                       AND F.FunctionType = 21
                                                                       INNER JOIN FUNCTION_PROPERTY_VALUE FPV ON FPV.Functionid = F.Id  
                                                                WHERE UPPER(OP.OperationRevision) = 'WRAPPER')                                                                                        
                                  WHERE  (TT.TextID IN  (SELECT TextId FROM COB_T_LT_TEXTID_SO_RECOMPILE WHERE IsProcessed = 0))                             
                                    UNION --Union Added by Yogesh
                                    SELECT Op.Id,Op.OperationCode,Op.OperationRevision
                                                                  FROM Function_Input Fi
                                                                      INNER JOIN Text_Translation TT
                                                                          ON ( TT.Textid    = Fi.Prompttextid
                                                                          AND TT.Active     =1)
                                                                          AND (TT.Short    <> 'Null'
                                                                          OR TT.Medium     <> 'Null'
                                                                          OR TT.Extended   <> 'Null')
                                                                      INNER JOIN Function_Input_Source_Type Fist
                                                                          ON Fist.Id     = Fi.Inputsourcetypeid
                                                                          AND Fist.Active=1
                                                                      INNER JOIN Text_Translation Ttdt
                                                                          ON Ttdt.Textid           = Fist.Textid
                                                                          AND Ttdt.Active          =1
                                                                          AND Ttdt.Languageid      = 1033
                                                                          AND Upper(Ttdt.Extended) = 'USER'
                                                                      INNER JOIN Function_ Fn
                                                                          ON Fn.Id     = Fi.Functionid
                                                                          AND Fn.Active=1
                                                                      INNER JOIN Function_Type Fnty
                                                                          ON Fn.Functiontype=Fnty.Functiontype
                                                                          AND Fnty.Active   =1
                                                                      INNER JOIN Operation_Step_Function Osf
                                                                          ON Osf.Functionid=Fn.Id
                                                                          AND Osf.Active   =1
                                                                      INNER JOIN Operation_Step Os
                                                                          ON Os.Id = Osf.Operationstepid
                                                                          AND Os.Active=1
                                                                      INNER JOIN Operation Op
                                                                         ON Op.Id = Os.Operationid                                
                                                                        AND Op.Active                =1
                                                                        And Op.Revisionstatusid In (1,4)
                                                                       INNER JOIN FUNCTION_INPUT_VALUE Fiv                 
                                                                            ON  Fi.id = Fiv.functionInputId AND Fiv.textid IS NOT NULL
                                                                        AND TO_CHAR(Op.Id) IN (SELECT DISTINCT TO_CHAR(SUBSTR(FPV.PropertyValue,INSTR(FPV.PropertyValue, '<PropertyBagItem Key="OperationID"><Value xsi:type="xsd:int">')+61,9))
                                                                                                FROM
                                                                                                       OPERATION OP
                                                                                                       INNER JOIN OPERATION_STEP OS ON Op.Id = OS.OperationId
                                                                                                       INNER JOIN OPERATION_STEP_FUNCTION OSF ON OS.Id = OSF.OperationStepId
                                                                                                       INNER JOIN   FUNCTION_ F ON OSF.FunctionId = F.id
                                                                                                       AND F.FunctionType = 21
                                                                                                       INNER JOIN FUNCTION_PROPERTY_VALUE FPV ON FPV.Functionid = F.Id  
                                                                                                WHERE UPPER(OP.OperationRevision) = 'WRAPPER')                                                                                        
                                                                  WHERE  (Fiv.TextID  IN  (SELECT TextId FROM COB_T_LT_TEXTID_SO_RECOMPILE WHERE IsProcessed = 0 ) )   
                                  MINUS
                                         (SELECT OperationId ,OperationCode,OperationRevision From COB_T_LANG_TRANS_OPERATION WHERE IsProcessed = 0)                                                                                    
                            DELETE FROM COB_T_LT_TEXTID_SO_RECOMPILE  where  IsProcessed = 0;        
                       END;         
                       END IF;                                       
    --            EXCEPTION
    --               WHEN OTHERS THEN
    --               ROLLBACK;
    --                   RAISE_APPLICATION_ERROR(-20660 , 'Concurrency violation. COB_T_LANG_TRANS_OPERATION table changed by another user in the meantime.');
                   END;                    
            END;          
    END;
    /

    Do you remember this thread of yours? {message:id=10653623}
    Well, you were asked to read various FAQs and to post certain information.
    You haven't read and you didn't post the required information.
    If you want people to make the effort to help you, you need to make the effort to post
    the required information.

  • Problem with setting oracle type parameter in viewobject query

    Hi There,
    I am facing a problem with JDev1013. I have a view that has JDBC positional parameters that are supposed to be in parameters for function like:
    SELECT x.day, x.special_exact_period_only
    FROM (
      SELECT x.day, x.special_exact_period_only
      FROM (
        SELECT
          x.day,
          rb.special_exact_period_only
      FROM TABLE (
        RentabilityPkg.findMarkerSlots(
          'start',
          ? /* dchannel */,
          NULL,
          ? /* resorts */,
          'special',
          NULL,
          ? /* code */,
          NULL,
          TRUNC(SYSDATE),
          TRUNC(SYSDATE + 365 * 2),
          NULL
      ) x
        JOIN resourcebase rb USING (rentabilitymanager_id)
        UNION
        SELECT
          x.day,
          rb.special_exact_period_only
        FROM TABLE (
          RentabilityPkg.findMarkerSlots(
            'start',
            ? /* dchannel */,
            NULL,
            ? /* resorts */,
            'composition',
            NULL,
            ? /* code */,
            NULL,
            TRUNC(SYSDATE),
            TRUNC(SYSDATE + 365 * 2),
            NULL
        ) x
        JOIN resourcebase rb USING (rentabilitymanager_id)
      )x
      ORDER BY x.day
    ) x
    WHERE ROWNUM <= 30now the JDBC positional parameters take our custom defined list type defined as:
    CREATE TYPE NumberList AS TABLE OF NUMBER;
    we are setting the parameter in the views with the help of oracle.sql.ARRAY class like:
       * Set parameters.
      public void setParams(Integer dchannelId, Integer[] resorts, String specialCode)
        try {
              System.out.println(this.getClass() + ".setParams()");
              ARRAY arrParam1 = ((NWSApplicationModule)getApplicationModule()).toSQLNumberList(Arrays.asList(resorts));
              ARRAY arrParam2 = ((NWSApplicationModule)getApplicationModule()).toSQLNumberList(Arrays.asList(resorts));
              System.out.println("arrParam1 - " + arrParam1);
              System.out.println("arrParam1 - " + arrParam1);
              System.out.println(this.getClass() + " ARRAY - " + arrParam1.getArray());
              System.out.println(this.getClass() + " -- " + arrParam1.length());
              System.out.println("arrParam2 - " + arrParam2);
              System.out.println("arrParam2 - " + arrParam2);
              System.out.println(this.getClass() + " ARRAY - " + arrParam2.getArray());
              System.out.println(this.getClass() + " -- " + arrParam2.length());
              Object[] params =
                   { dchannelId,
                        arrParam1,
                        specialCode,
                        dchannelId,
                        arrParam2,
                        specialCode
              setWhereClauseParams(params);
              System.out.println("DONE WITH " + this.getClass() + ".setParams()");
        catch(Exception ex)
              ex.printStackTrace(System.out);
      }the toSQLNumberList() method is defined in our App module baseclass as follows:
      public ARRAY toSQLNumberList(Collection coll)
           debug("toSQLNumberList()");
           DBTransaction txn = (DBTransaction)getTransaction();
           debug("txn - " + txn + " : " + txn.getClass());
           return NWSUtil.toSQLNumberList(coll, getConnection(txn));
      public static ARRAY toSQLNumberList(Collection c, Connection connection)
        //printTrace();
        debug("toSQLNumberList()");
        try
          ArrayDescriptor numberList = ArrayDescriptor.createDescriptor("NUMBERLIST", connection);
          NUMBER[] elements = new NUMBER[c == null ? 0 : c.size()];
          if (elements.length > 0 )
            Iterator iter = c.iterator();
            for (int i = 0; iter.hasNext(); i++)
              elements[i] = new NUMBER(iter.next().toString());
          return new ARRAY(numberList, connection, elements);
        catch (Exception ex)
          ex.printStackTrace();
          return null;
      protected Connection getConnection(DBTransaction dbTransaction)
        //return null;
        debug("Inside getConnection()");
        CallableStatement s = null;
        try
           * Getting Conenction in BC4J is dirty but its better
           * as otherwise we might end up coding with connections
           * and the Transaction Integrety will be
          s = dbTransaction.createCallableStatement("BEGIN NULL; END;", 0);
          debug("DOING s.getConnection()...");
          Connection conn = s.getConnection();
          debug("DONE WITH  s.getConnection()...");
          /*try
                throw new Exception("TEST");
           catch (Exception ex)
                ex.printStackTrace(System.out);
          debug("conn CLASS - " + conn.getClass());
          return conn;
        catch (Exception ex)
          ex.printStackTrace();
          return null;
        finally
          try { s.close(); }
          catch (Exception ex) {}
      }Whenever we try setting the parameters in view using setParams() and use this view to set the model of a java control it thorws the following exception :
    [2006-10-10 12:34:48,797 AWT-EventQueue-0 ERROR] JBO-28302: Piggyback write error
    oracle.jbo.PiggybackException: JBO-28302: Piggyback write error
         at oracle.jbo.common.PiggybackOutput.getPiggybackStream(PiggybackOutput.java:185)
         at oracle.jbo.common.JboServiceMessage.marshalRefs(JboServiceMessage.java:267)
         at oracle.jbo.server.remote.PiggybackManager.marshalServiceMessage(PiggybackManager.java:343)
         at oracle.jbo.server.remote.PiggybackManager.marshalServiceMessage(PiggybackManager.java:316)
         at oracle.jbo.server.remote.AbstractRemoteApplicationModuleImpl.processMessage(AbstractRemoteApplicationModuleImpl.java:2283)
         at oracle.jbo.server.ApplicationModuleImpl.doMessage(ApplicationModuleImpl.java:7509)
         at oracle.jbo.server.remote.AbstractRemoteApplicationModuleImpl.sync(AbstractRemoteApplicationModuleImpl.java:2221)
         at oracle.jbo.server.remote.ejb.ServerApplicationModuleImpl.doMessage(ServerApplicationModuleImpl.java:79)
         at oracle.jbo.server.ejb.SessionBeanImpl.doMessage(SessionBeanImpl.java:474)
         at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at com.evermind.server.ejb.interceptor.joinpoint.EJBJoinPointImpl.invoke(EJBJoinPointImpl.java:35)
         at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:69)
         at com.evermind.server.ejb.interceptor.system.DMSInterceptor.invoke(DMSInterceptor.java:52)
         at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:69)
         at com.evermind.server.ejb.interceptor.system.TxBeanManagedInterceptor.invoke(TxBeanManagedInterceptor.java:53)
         at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:69)
         at com.evermind.server.ejb.interceptor.system.DMSInterceptor.invoke(DMSInterceptor.java:52)
         at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:69)
         at com.evermind.server.ejb.StatefulSessionEJBObject.OC4J_invokeMethod(StatefulSessionEJBObject.java:840)
         at RemoteAMReservation_StatefulSessionBeanWrapper906.doMessage(RemoteAMReservation_StatefulSessionBeanWrapper906.java:286)
         at sun.reflect.GeneratedMethodAccessor63.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at com.evermind.server.rmi.RmiMethodCall.run(RmiMethodCall.java:53)
         at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
         at java.lang.Thread.run(Thread.java:595)
    ## Detail 0 ##
    java.io.NotSerializableException: oracle.jdbc.driver.T4CConnection
         at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1075)
         at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1369)
         at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1341)
         at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)
         at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
         at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1245)
         at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1069)
         at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1245)
         at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1069)
         at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:291)
         at oracle.jbo.common.SvcMsgResponseValues.writeObject(SvcMsgResponseValues.java:116)
         at sun.reflect.GeneratedMethodAccessor65.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:890)
         at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1333)
         at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)
         at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
         at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:291)
         at oracle.jbo.common.PiggybackOutput.getPiggybackStream(PiggybackOutput.java:173)
         at oracle.jbo.common.JboServiceMessage.marshalRefs(JboServiceMessage.java:267)
         at oracle.jbo.server.remote.PiggybackManager.marshalServiceMessage(PiggybackManager.java:343)
         at oracle.jbo.server.remote.PiggybackManager.marshalServiceMessage(PiggybackManager.java:316)
         at oracle.jbo.server.remote.AbstractRemoteApplicationModuleImpl.processMessage(AbstractRemoteApplicationModuleImpl.java:2283)
         at oracle.jbo.server.ApplicationModuleImpl.doMessage(ApplicationModuleImpl.java:7509)
         at oracle.jbo.server.remote.AbstractRemoteApplicationModuleImpl.sync(AbstractRemoteApplicationModuleImpl.java:2221)
         at oracle.jbo.server.remote.ejb.ServerApplicationModuleImpl.doMessage(ServerApplicationModuleImpl.java:79)
         at oracle.jbo.server.ejb.SessionBeanImpl.doMessage(SessionBeanImpl.java:474)
         at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at com.evermind.server.ejb.interceptor.joinpoint.EJBJoinPointImpl.invoke(EJBJoinPointImpl.java:35)
         at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:69)
         at com.evermind.server.ejb.interceptor.system.DMSInterceptor.invoke(DMSInterceptor.java:52)
         at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:69)
         at com.evermind.server.ejb.interceptor.system.TxBeanManagedInterceptor.invoke(TxBeanManagedInterceptor.java:53)
         at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:69)
         at com.evermind.server.ejb.interceptor.system.DMSInterceptor.invoke(DMSInterceptor.java:52)
         at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:69)
         at com.evermind.server.ejb.StatefulSessionEJBObject.OC4J_invokeMethod(StatefulSessionEJBObject.java:840)
         at RemoteAMReservation_StatefulSessionBeanWrapper906.doMessage(RemoteAMReservation_StatefulSessionBeanWrapper906.java:286)
         at sun.reflect.GeneratedMethodAccessor63.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at com.evermind.server.rmi.RmiMethodCall.run(RmiMethodCall.java:53)
         at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
         at java.lang.Thread.run(Thread.java:595)This is a typical interaction between 2 server-side components (view-object and app module). Now the question is why is this exception thrown? Any answers?
    This application is one that we have migrated from 904 to 1013 and are trying to get it running in 3-tier.
    Regards,
    Anupam

    Sorry I missed out some semicolons, the script follws:
    -- The following TABLE was created to simulate the issue
    CREATE TABLE TEST_OBJECT
         ASSET_ID NUMBER,
         OBJECT_ID NUMBER,
         NAME VARCHAR2(50)
    INSERT INTO TEST_OBJECT VALUES(1,1,'AAA');
    INSERT INTO TEST_OBJECT VALUES(2,2,'BBB');
    INSERT INTO TEST_OBJECT VALUES(3,3,'CCC');
    COMMIT;
    SELECT * FROM TEST_OBJECT;
    -- The following TYPES was created to simulate the issue
    CREATE OR REPLACE
    TYPE DUTYRESULTOBJECTTAB AS TABLE OF DUTYRESULTOBJECT;
    CREATE OR REPLACE
    type DutyResultObject as object
    ( ASSET_ID number,
      OBJECT_ID number,
      NAME varchar2(150)
    -- The following PACKAGE N FUNCTION was created to simulate the issue
    CREATE OR REPLACE PACKAGE TESTOBJECTPKG
    IS
         FUNCTION OBJECTSEARCH(P_RESOURCE IN NUMBERLIST) RETURN DUTYRESULTOBJECTTAB;
    END;
    CREATE OR REPLACE PACKAGE BODY TESTOBJECTPKG
    IS
         FUNCTION OBJECTSEARCH(P_RESOURCE IN NUMBERLIST) RETURN DUTYRESULTOBJECTTAB
         IS
           BULKDUTYRESULTOBJECTTAB DUTYRESULTOBJECTTAB;
         BEGIN
           SELECT DUTYRESULTOBJECT(ASSET_ID, OBJECT_ID, NAME)
           BULK COLLECT INTO BULKDUTYRESULTOBJECTTAB
           FROM TEST_OBJECT;
           RETURN BULKDUTYRESULTOBJECTTAB;
         END;
    END;
    [\code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Approach to tune a query in short time

    Hi All,
    Oracle 10g I know this question is asked number of times and there are many good replies to them.
    But I just want to know how to approach a completely new query ( like the task given to me to fine tume a query in 1 day when I dont have even the slightest idea about how to proceed) if the timeline is very stringent and by just looking at the explain plan, you have to take the decision.
    I am just posting my query here and what I am looking for is some lead on how to identify the congetion point which is where this query takes long time ( in my case some 15 mins as reported to me)
    select
                     "LEGAL ENTITY",
                     "Legal Entity Description",
                     "Cluster",
                     "Sub_Cluster",
                     "Account",
                      rownum,
                     "Moody_Rating",
                     "Process_Date",
                     "Merge_Description",
                      rownum,
                     "Merge_Description",
                     "is_id_ic",
                     "is_n",
                     "cusip",
                     "isin",
                     "credit_spread_PV01",
                     "amount",
                     "Market_Value",
                     "Currency",
                     "Sensitivity_Type",
                     "maturity_Date",
                     "Exception_Flag",
                     "Base_Security_Id",
                     DECODE(sign("Market_Value"),-1,DeCode(SigN("Recovery"),-1,"Recovery",('-'||"Recovery")), ABS("Recovery")) as "Recovery"
                     from
                     select
                     le.name "LEGAL ENTITY",
                     le.display_name "Legal Entity Description",
                     mn4.display_name "Cluster",
                     mn3.display_name "Sub_Cluster",
                     bookname.display_name "Account",
                     (SELECT RATING_NAME
                        FROM moody_rating
                       where moody_rating_id = i.moody_rating_id) "Moody_Rating",
                     to_char(to_date(:v_cob_date,'DD-MM-YY'),'YYYYMMDD') "Process_Date",
                     ss.issuer "Merge_Description",
                     PART.MARS_ISSUER "is_id_ic",
                     PART.PARTICIPANT_NAME "is_n",
                     NULL "cusip",
                     NULL "isin",
                     NULL "credit_spread_PV01",
                     NULL "amount",
                     sum(mtmsens.sensitivity_value) "Market_Value",
                     (SELECT distinct cc.CCY
                        FROM legacy_country CC
                       INNER JOIN MARSNODE MN ON CC.countryisocode = MN.NAME
                                             and mn.close_date is null
                       INNER JOIN MARSNODETYPE MNT ON MN.TYPE_ID =
                                                      MNT.NODE_TYPE_ID
                                                  AND MNT.NAME = 'COUNTRY'
                                                  and mnt.close_date is null
                       where MN.NODE_ID = part.country_domicile_id
                         and cc.begin_cob_date <= :v_cob_date
                         and cc.end_cob_date > :v_cob_date
                         and rownum < 2) "Currency",
                     'CREDITSPREADMARKETVALUE' "Sensitivity_Type",
                     NULL "maturity_Date",
                     NULL "Exception_Flag",
                     NULL "Base_Security_Id",
                     sum(ss.sensitivity_value) "Recovery"
                     from staging_position sp
                left JOIN position p on (
                                         p.feed_instance_id = sp.feed_instance_id
                                     AND p.feed_row_id = sp.feed_row_id)
                left JOIN staging_instrument si on (si.feed_instance_id =
                                                   sp.feed_instance_id AND
                                                   si.position_key =
                                                   sp.position_key)
                left join book b on (b.book_id = p.book_id and
                                    b.begin_cob_date <= :v_cob_date and
                                    b.end_cob_date > :v_cob_date)
                left join marsnode bk on (b.book_id = bk.node_id and
                                         bk.close_date is null)
                left join marsnode le on (b.leg_ent_id = le.node_id and
                                         le.close_date is null)
                left join marsnode bookname on (bookname.node_id = p.book_id and
                                               bookname.close_date is null)
                left join marsnodelink mnl on p.book_id = mnl.node_id
                                          and :v_bus_org_hier_id =
                                              mnl.hierarchy_id
                                          and mnl.close_date is null
                                          and :v_cob_date >= mnl.begin_cob_date
                                          and :v_cob_date < mnl.end_cob_date
                left join marsnode mn on mn.node_id = mnl.parent_id
                                     and mn.close_date is null
                left join marsnodelink mnl2 on mn.node_id = mnl2.node_id
                                           and :v_bus_org_hier_id =
                                               mnl2.hierarchy_id
                                           and mnl2.close_date is null
                                           and :v_cob_date >= mnl2.begin_cob_date
                                           and :v_cob_date < mnl2.end_cob_date
                left join marsnode mn2 on mn2.node_id = mnl2.parent_id
                                      and mn2.close_date is null
                left join marsnodelink mnl3 on mn2.node_id = mnl3.node_id
                                           and :v_bus_org_hier_id =
                                               mnl3.hierarchy_id
                                           and mnl3.close_date is null
                                           and :v_cob_date >= mnl3.begin_cob_date
                                           and :v_cob_date < mnl3.end_cob_date
                left join marsnode mn3 on mn3.node_id = mnl3.parent_id
                                      and mn3.close_date is null
                left join marsnodelink mnl4 on mn3.node_id = mnl4.node_id
                                           and :v_bus_org_hier_id =
                                               mnl4.hierarchy_id
                                           and mnl4.close_date is null
                                           and :v_cob_date >= mnl4.begin_cob_date
                                           and :v_cob_date < mnl4.end_cob_date
                left join marsnode mn4 on mn4.node_id = mnl4.parent_id
                                      and mn4.close_date is null
              --sensitivity data
                left JOIN STAGING_SENSITIVITY ss ON (ss.FEED_INSTANCE_ID =
                                                    sp.FEED_INSTANCE_ID AND
                                                    ss.FEED_ROW_ID =
                                                    sp.FEED_ROW_ID)
              --sensitivity data
                left JOIN STAGING_SENSITIVITY mtmsens ON (mtmsens.FEED_INSTANCE_ID =
                                                         sp.FEED_INSTANCE_ID AND
                                                         mtmsens.FEED_ROW_ID =
                                                         sp.FEED_ROW_ID)
                LEFT join xref_domain_value_map XREF on (XREF.Src_Value =
                                                        ss.issuer and
                                                        XREF.close_action_id is null and
                                                        XREF.Begin_Cob_Date <=
                                                        :v_cob_date and
                                                        XREF.End_Cob_Date >
                                                        :v_cob_date AND
                                                        xref.domain_map_id = 601 AND
                                                        xref.source_system_id = 307 AND xref.ISSUE_ID is not null)
                Left join ISSUE i on (i.issue_id = xref.issue_id)
                LEFT join participant PART ON (PART.PARTICIPANT_ID =
                                              XREF.TGT_VALUE and
                                              PART.Close_Action_Id is null and
                                              PART.Begin_Cob_Date <= :v_cob_date and
                                              PART.End_Cob_Date > :v_cob_date)
                left join moody_rating RATING on (rating.moody_rating_id =
                                                  i.MOODY_RATING_ID)
               where sp.feed_instance_id in
                     (select fbi.feed_instance_id
                      from   feed_book_status fbi ,
                             feed_instance fi
                      where  fbi.cob_date = :v_cob_date
                      and    fbi.feed_instance_id = fi.feed_instance_id
                      and    fi.feed_id in (
                                           select feed_id from feed_group_xref where feed_group_id in (
                                               select feed_group_id from feed_group where description like 'CDO Feeds')
                                               and close_action_id is null
                 and sp.Feed_Row_Status_Id = 1
                 and ss.sensitivity_type = 'CREDITSPREADDEFAULT'
                 and mtmsens.sensitivity_type = 'MTMVALUE'
                 and le.name='161'
                 group by le.name,
                        le.display_name,
                        mn3.display_name,
                        mn4.display_name,
                        mn.display_name,
                        i.moody_rating_id,
                        ss.issuer,
                        PART.MARS_ISSUER,
                        PART.PARTICIPANT_NAME,
                        sp.feed_instance_id,
                        part.country_domicile_id,
                        bookname.display_name) And the explain plan
    SELECT STATEMENT, GOAL = CHOOSE               Cost=19365     Cardinality=1     Bytes=731
    TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MOODY_RATING     Cost=1     Cardinality=1     Bytes=9
      INDEX UNIQUE SCAN     Object owner=MARS     Object name=PK_MOODY_RATING     Cost=0     Cardinality=1     
    HASH UNIQUE               Cost=77     Cardinality=1     Bytes=488
      COUNT STOPKEY                         
       HASH JOIN               Cost=76     Cardinality=1     Bytes=488
        NESTED LOOPS               Cost=68     Cardinality=1     Bytes=460
         HASH JOIN               Cost=66     Cardinality=1     Bytes=450
          HASH JOIN               Cost=59     Cardinality=1     Bytes=412
           NESTED LOOPS               Cost=51     Cardinality=1     Bytes=402
            HASH JOIN               Cost=49     Cardinality=1     Bytes=392
             NESTED LOOPS               Cost=42     Cardinality=1     Bytes=359
              NESTED LOOPS               Cost=40     Cardinality=1     Bytes=349
               NESTED LOOPS               Cost=37     Cardinality=1     Bytes=300
                NESTED LOOPS               Cost=34     Cardinality=1     Bytes=251
                 HASH JOIN               Cost=32     Cardinality=1     Bytes=241
                  TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MARSNODE     Cost=3     Cardinality=1     Bytes=27
                   NESTED LOOPS               Cost=24     Cardinality=1     Bytes=231
                    NESTED LOOPS               Cost=21     Cardinality=1     Bytes=204
                     NESTED LOOPS               Cost=18     Cardinality=1     Bytes=171
                      NESTED LOOPS               Cost=16     Cardinality=1     Bytes=136
                       NESTED LOOPS               Cost=13     Cardinality=1     Bytes=86
                        NESTED LOOPS               Cost=10     Cardinality=1     Bytes=37
                         VIEW     Object owner=MARS          Cost=7     Cardinality=1     Bytes=10
                          FILTER                         
                           CONNECT BY WITH FILTERING                         
                            TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MARSNODELINK               
                             INDEX RANGE SCAN     Object owner=MARS     Object name=FKI_15632_PARENT_ID     Cost=3     Cardinality=250     Bytes=2500
                              HASH JOIN               Cost=5     Cardinality=1     Bytes=62
                               TABLE ACCESS FULL     Object owner=MARS     Object name=MARSHIERARCHY     Cost=2     Cardinality=1     Bytes=27
                               TABLE ACCESS FULL     Object owner=MARS     Object name=MARSHIERARCHYROOT     Cost=2     Cardinality=5     Bytes=175
                            NESTED LOOPS                         
                             CONNECT BY PUMP                         
                             TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MARSNODELINK     Cost=7     Cardinality=1     Bytes=39
                              INDEX RANGE SCAN     Object owner=MARS     Object name=IDX_MNL_HI_PI_NI     Cost=3     Cardinality=4     
                           TABLE ACCESS FULL     Object owner=MARS     Object name=MARSHIERARCHY     Cost=2     Cardinality=1     Bytes=27
                         TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MARSNODE     Cost=3     Cardinality=1     Bytes=27
                          INDEX RANGE SCAN     Object owner=MARS     Object name=PK_MARSNODE     Cost=2     Cardinality=1     
                        TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MARSNODE     Cost=3     Cardinality=1     Bytes=49
                         INDEX RANGE SCAN     Object owner=MARS     Object name=PK_MARSNODE     Cost=2     Cardinality=1     
                       TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MARSNODE     Cost=3     Cardinality=1     Bytes=50
                        INDEX RANGE SCAN     Object owner=MARS     Object name=PK_MARSNODE     Cost=2     Cardinality=1     
                      TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MARSNODETYPE     Cost=2     Cardinality=1     Bytes=35
                       INDEX RANGE SCAN     Object owner=MARS     Object name=PK_MARSNODETYPE     Cost=1     Cardinality=1     
                     TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=NODE_ASSOC     Cost=3     Cardinality=1     Bytes=33
                      INDEX RANGE SCAN     Object owner=MARS     Object name=PK_NODE_ASSOC     Cost=1     Cardinality=3     
                    INDEX RANGE SCAN     Object owner=MARS     Object name=PK_MARSNODE     Cost=2     Cardinality=1     
                  VIEW     Object owner=MARS          Cost=7     Cardinality=1     Bytes=10
                   FILTER                         
                    CONNECT BY WITH FILTERING                         
                     TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MARSNODELINK               
                      INDEX RANGE SCAN     Object owner=MARS     Object name=FKI_15632_PARENT_ID     Cost=3     Cardinality=250     Bytes=2500
                       HASH JOIN               Cost=5     Cardinality=1     Bytes=62
                        TABLE ACCESS FULL     Object owner=MARS     Object name=MARSHIERARCHY     Cost=2     Cardinality=1     Bytes=27
                        TABLE ACCESS FULL     Object owner=MARS     Object name=MARSHIERARCHYROOT     Cost=2     Cardinality=5     Bytes=175
                     NESTED LOOPS                         
                      CONNECT BY PUMP                         
                      TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MARSNODELINK     Cost=7     Cardinality=1     Bytes=39
                       INDEX RANGE SCAN     Object owner=MARS     Object name=IDX_MNL_HI_PI_NI     Cost=3     Cardinality=4     
                    TABLE ACCESS FULL     Object owner=MARS     Object name=MARSHIERARCHY     Cost=2     Cardinality=1     Bytes=27
                 INDEX RANGE SCAN     Object owner=MARS     Object name=PK_MARSNODE     Cost=2     Cardinality=1     Bytes=10
                TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=NODE_ASSOC     Cost=3     Cardinality=1     Bytes=49
                 INDEX RANGE SCAN     Object owner=MARS     Object name=PK_NODE_ASSOC     Cost=1     Cardinality=3     
               TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MARSNODE     Cost=3     Cardinality=1     Bytes=49
                INDEX RANGE SCAN     Object owner=MARS     Object name=PK_MARSNODE     Cost=2     Cardinality=1     
              INDEX RANGE SCAN     Object owner=MARS     Object name=PK_MARSNODE     Cost=2     Cardinality=1     Bytes=10
             VIEW     Object owner=MARS          Cost=7     Cardinality=1     Bytes=33
              FILTER                         
               CONNECT BY WITH FILTERING                         
                TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MARSNODELINK               
                 INDEX RANGE SCAN     Object owner=MARS     Object name=FKI_15632_PARENT_ID     Cost=3     Cardinality=250     Bytes=2500
                  HASH JOIN               Cost=5     Cardinality=1     Bytes=62
                   TABLE ACCESS FULL     Object owner=MARS     Object name=MARSHIERARCHY     Cost=2     Cardinality=1     Bytes=27
                   TABLE ACCESS FULL     Object owner=MARS     Object name=MARSHIERARCHYROOT     Cost=2     Cardinality=5     Bytes=175
                NESTED LOOPS                         
                 CONNECT BY PUMP                         
                 TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MARSNODELINK     Cost=7     Cardinality=1     Bytes=39
                  INDEX RANGE SCAN     Object owner=MARS     Object name=IDX_MNL_HI_PI_NI     Cost=3     Cardinality=4     
               TABLE ACCESS FULL     Object owner=MARS     Object name=MARSHIERARCHY     Cost=2     Cardinality=1     Bytes=27
            INDEX RANGE SCAN     Object owner=MARS     Object name=PK_MARSNODE     Cost=2     Cardinality=1     Bytes=10
           VIEW     Object owner=MARS          Cost=7     Cardinality=1     Bytes=10
            FILTER                         
             CONNECT BY WITH FILTERING                         
              TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MARSNODELINK               
               INDEX RANGE SCAN     Object owner=MARS     Object name=FKI_15632_PARENT_ID     Cost=3     Cardinality=250     Bytes=2500
                HASH JOIN               Cost=5     Cardinality=1     Bytes=62
                 TABLE ACCESS FULL     Object owner=MARS     Object name=MARSHIERARCHY     Cost=2     Cardinality=1     Bytes=27
                 TABLE ACCESS FULL     Object owner=MARS     Object name=MARSHIERARCHYROOT     Cost=2     Cardinality=5     Bytes=175
              NESTED LOOPS                         
               CONNECT BY PUMP                         
               TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MARSNODELINK     Cost=7     Cardinality=1     Bytes=39
                INDEX RANGE SCAN     Object owner=MARS     Object name=IDX_MNL_HI_PI_NI     Cost=3     Cardinality=4     
             TABLE ACCESS FULL     Object owner=MARS     Object name=MARSHIERARCHY     Cost=2     Cardinality=1     Bytes=27
          VIEW     Object owner=MARS          Cost=7     Cardinality=1     Bytes=38
           FILTER                         
            CONNECT BY WITH FILTERING                         
             TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MARSNODELINK               
              INDEX RANGE SCAN     Object owner=MARS     Object name=FKI_15632_PARENT_ID     Cost=3     Cardinality=250     Bytes=2500
               HASH JOIN               Cost=5     Cardinality=1     Bytes=62
                TABLE ACCESS FULL     Object owner=MARS     Object name=MARSHIERARCHY     Cost=2     Cardinality=1     Bytes=27
                TABLE ACCESS FULL     Object owner=MARS     Object name=MARSHIERARCHYROOT     Cost=2     Cardinality=5     Bytes=175
             NESTED LOOPS                         
              CONNECT BY PUMP                         
              TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MARSNODELINK     Cost=7     Cardinality=1     Bytes=57
               INDEX RANGE SCAN     Object owner=MARS     Object name=IDX_MNL_HI_PI_NI     Cost=3     Cardinality=4     
            TABLE ACCESS FULL     Object owner=MARS     Object name=MARSHIERARCHY     Cost=2     Cardinality=1     Bytes=36
         INDEX RANGE SCAN     Object owner=MARS     Object name=PK_MARSNODE     Cost=2     Cardinality=1     Bytes=10
        VIEW     Object owner=MARS          Cost=7     Cardinality=1     Bytes=28
         FILTER                         
          CONNECT BY WITH FILTERING                         
           TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MARSNODELINK               
            INDEX RANGE SCAN     Object owner=MARS     Object name=FKI_15632_PARENT_ID     Cost=3     Cardinality=250     Bytes=2500
             HASH JOIN               Cost=5     Cardinality=1     Bytes=62
              TABLE ACCESS FULL     Object owner=MARS     Object name=MARSHIERARCHY     Cost=2     Cardinality=1     Bytes=27
              TABLE ACCESS FULL     Object owner=MARS     Object name=MARSHIERARCHYROOT     Cost=2     Cardinality=5     Bytes=175
           NESTED LOOPS                         
            CONNECT BY PUMP                         
            TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MARSNODELINK     Cost=7     Cardinality=1     Bytes=57
             INDEX RANGE SCAN     Object owner=MARS     Object name=IDX_MNL_HI_PI_NI     Cost=3     Cardinality=4     
          TABLE ACCESS FULL     Object owner=MARS     Object name=MARSHIERARCHY     Cost=2     Cardinality=1     Bytes=27
    COUNT                         
      VIEW     Object owner=MARS          Cost=19365     Cardinality=1     Bytes=731
       HASH GROUP BY               Cost=19365     Cardinality=1     Bytes=1112
        NESTED LOOPS OUTER               Cost=19364     Cardinality=1     Bytes=1112
         NESTED LOOPS OUTER               Cost=19361     Cardinality=1     Bytes=1040
          NESTED LOOPS OUTER               Cost=19361     Cardinality=1     Bytes=1037
           NESTED LOOPS OUTER               Cost=19360     Cardinality=1     Bytes=1019
            NESTED LOOPS OUTER               Cost=19357     Cardinality=1     Bytes=951
             NESTED LOOPS OUTER               Cost=19354     Cardinality=1     Bytes=914
              NESTED LOOPS OUTER               Cost=19351     Cardinality=1     Bytes=877
               NESTED LOOPS OUTER               Cost=19337     Cardinality=1     Bytes=820
                NESTED LOOPS OUTER               Cost=19334     Cardinality=1     Bytes=783
                 NESTED LOOPS OUTER               Cost=19320     Cardinality=1     Bytes=726
                  NESTED LOOPS OUTER               Cost=19317     Cardinality=1     Bytes=707
                   NESTED LOOPS OUTER               Cost=19303     Cardinality=1     Bytes=650
                    NESTED LOOPS OUTER               Cost=19300     Cardinality=1     Bytes=613
                     NESTED LOOPS               Cost=19285     Cardinality=1     Bytes=556
                      NESTED LOOPS               Cost=19280     Cardinality=1     Bytes=443
                       NESTED LOOPS OUTER               Cost=19275     Cardinality=1     Bytes=330
                        HASH JOIN RIGHT SEMI               Cost=17457     Cardinality=1     Bytes=248
                         VIEW     Object owner=SYS     Object name=VW_NSO_1     Cost=1119     Cardinality=30     Bytes=150
                          HASH JOIN               Cost=1119     Cardinality=30     Bytes=2040
                           TABLE ACCESS FULL     Object owner=MARS     Object name=FEED_GROUP     Cost=2     Cardinality=5     Bytes=120
                           HASH JOIN               Cost=1116     Cardinality=1607     Bytes=70708
                            TABLE ACCESS FULL     Object owner=MARS     Object name=FEED_GROUP_XREF     Cost=13     Cardinality=701     Bytes=14721
                            HASH JOIN               Cost=1102     Cardinality=3602     Bytes=82846
                             INDEX RANGE SCAN     Object owner=MARS     Object name=IDX_FBS_CD_FII_BI     Cost=22     Cardinality=3602     Bytes=46826
                             TABLE ACCESS FULL     Object owner=MARS     Object name=FEED_INSTANCE     Cost=1024     Cardinality=670264     Bytes=6702640
                         NESTED LOOPS               Cost=16337     Cardinality=324     Bytes=78732
                          HASH JOIN               Cost=14324     Cardinality=1977     Bytes=302481
                           NESTED LOOPS OUTER               Cost=11     Cardinality=1     Bytes=114
                            NESTED LOOPS               Cost=8     Cardinality=1     Bytes=95
                             TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MARSNODE     Cost=5     Cardinality=1     Bytes=59
                              INDEX RANGE SCAN     Object owner=MARS     Object name=IDX_NODE1     Cost=3     Cardinality=2     
                             TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=BOOK     Cost=3     Cardinality=2     Bytes=72
                              INDEX RANGE SCAN     Object owner=MARS     Object name=IDX_BOOK_LEI_BCD     Cost=2     Cardinality=4     
                            TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MARSNODE     Cost=3     Cardinality=1     Bytes=19
                             INDEX RANGE SCAN     Object owner=MARS     Object name=PK_MARSNODE     Cost=2     Cardinality=1     
                           PARTITION RANGE ALL               Cost=13995     Cardinality=3854299     Bytes=150317661
                            TABLE ACCESS FULL     Object owner=MARS     Object name=POSITION     Cost=13995     Cardinality=3854299     Bytes=150317661
                          PARTITION RANGE ITERATOR               Cost=2     Cardinality=1     Bytes=90
                           PARTITION HASH ITERATOR               Cost=2     Cardinality=1     Bytes=90
                            TABLE ACCESS BY LOCAL INDEX ROWID     Object owner=MARS     Object name=STAGING_POSITION     Cost=2     Cardinality=1     Bytes=90
                             INDEX UNIQUE SCAN     Object owner=MARS     Object name=PK_STAGINGPOSITON     Cost=1     Cardinality=1     
                        PARTITION HASH ITERATOR               Cost=1819     Cardinality=1     Bytes=82
                         TABLE ACCESS BY LOCAL INDEX ROWID     Object owner=MARS     Object name=STAGING_INSTRUMENT     Cost=1819     Cardinality=1     Bytes=82
                          INDEX RANGE SCAN     Object owner=MARS     Object name=PK_STAGINGINSTRUMENT     Cost=9     Cardinality=2551     
                       PARTITION RANGE ITERATOR               Cost=5     Cardinality=1     Bytes=113
                        PARTITION HASH ITERATOR               Cost=5     Cardinality=1     Bytes=113
                         TABLE ACCESS BY LOCAL INDEX ROWID     Object owner=MARS     Object name=STAGING_SENSITIVITY     Cost=5     Cardinality=1     Bytes=113
                          INDEX RANGE SCAN     Object owner=MARS     Object name=IDX_SENSITIVITY_FEED_ROW_ID     Cost=3     Cardinality=8     
                      PARTITION RANGE ITERATOR               Cost=5     Cardinality=1     Bytes=113
                       PARTITION HASH ITERATOR               Cost=5     Cardinality=1     Bytes=113
                        TABLE ACCESS BY LOCAL INDEX ROWID     Object owner=MARS     Object name=STAGING_SENSITIVITY     Cost=5     Cardinality=1     Bytes=113
                         INDEX RANGE SCAN     Object owner=MARS     Object name=IDX_SENSITIVITY_FEED_ROW_ID     Cost=3     Cardinality=8     
                     TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MARSNODELINK     Cost=14     Cardinality=1     Bytes=57
                      INDEX RANGE SCAN     Object owner=MARS     Object name=FKI_15632_NODE_ID     Cost=2     Cardinality=14     
                    TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MARSNODE     Cost=3     Cardinality=1     Bytes=37
                     INDEX RANGE SCAN     Object owner=MARS     Object name=PK_MARSNODE     Cost=2     Cardinality=1     
                   TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MARSNODELINK     Cost=14     Cardinality=1     Bytes=57
                    INDEX RANGE SCAN     Object owner=MARS     Object name=FKI_15632_NODE_ID     Cost=2     Cardinality=14     
                  TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MARSNODE     Cost=3     Cardinality=1     Bytes=19
                   INDEX RANGE SCAN     Object owner=MARS     Object name=PK_MARSNODE     Cost=2     Cardinality=1     
                 TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MARSNODELINK     Cost=14     Cardinality=1     Bytes=57
                  INDEX RANGE SCAN     Object owner=MARS     Object name=FKI_15632_NODE_ID     Cost=2     Cardinality=14     
                TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MARSNODE     Cost=3     Cardinality=1     Bytes=37
                 INDEX RANGE SCAN     Object owner=MARS     Object name=PK_MARSNODE     Cost=2     Cardinality=1     
               TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MARSNODELINK     Cost=14     Cardinality=1     Bytes=57
                INDEX RANGE SCAN     Object owner=MARS     Object name=FKI_15632_NODE_ID     Cost=2     Cardinality=14     
              TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MARSNODE     Cost=3     Cardinality=1     Bytes=37
               INDEX RANGE SCAN     Object owner=MARS     Object name=PK_MARSNODE     Cost=2     Cardinality=1     
             TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=MARSNODE     Cost=3     Cardinality=1     Bytes=37
              INDEX RANGE SCAN     Object owner=MARS     Object name=PK_MARSNODE     Cost=2     Cardinality=1     
            TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=XREF_DOMAIN_VALUE_MAP     Cost=3     Cardinality=1     Bytes=68
             INDEX RANGE SCAN     Object owner=MARS     Object name=IDX_XDVM_DMI_SV_BCD     Cost=2     Cardinality=1     
           TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=ISSUE     Cost=1     Cardinality=1     Bytes=18
            INDEX UNIQUE SCAN     Object owner=MARS     Object name=PK_ISSUE     Cost=0     Cardinality=1     
          INDEX UNIQUE SCAN     Object owner=MARS     Object name=PK_MOODY_RATING     Cost=0     Cardinality=1     Bytes=3
         TABLE ACCESS BY INDEX ROWID     Object owner=MARS     Object name=PARTICIPANT     Cost=3     Cardinality=1     Bytes=72
          INDEX RANGE SCAN     Object owner=MARS     Object name=PK_PARTICIPANT     Cost=2     Cardinality=1     

    Hi,
    in your explain plan:
    HASH JOIN RIGHT SEMI               Cost=17457     Cardinality=1     Bytes=248
    VIEW     Object owner=SYS     Object name=VW_NSO_1     Cost=1119     Cardinality=30     Bytes=150
    HASH JOIN               Cost=1119     Cardinality=30     Bytes=2040
    TABLE ACCESS FULL     Object owner=MARS     Object name=FEED_GROUP     Cost=2     Cardinality=5     Bytes=120
    HASH JOIN               Cost=1116     Cardinality=1607     Bytes=70708
    TABLE ACCESS FULL     Object owner=MARS     Object name=FEED_GROUP_XREF     Cost=13     Cardinality=701     Bytes=14721
    HASH JOIN               Cost=1102     Cardinality=3602     Bytes=82846
    INDEX RANGE SCAN     Object owner=MARS     Object name=IDX_FBS_CD_FII_BI     Cost=22     Cardinality=3602     Bytes=46826
    TABLE ACCESS FULL     Object owner=MARS     Object name=FEED_INSTANCEThis part has the highest costs (this doesn't always mean it is slow). So this leads me to the WHERE clause where feed_group, feed_group_xref and feed_instance full are used. Maybe this can be improved, although the cardinality is not that high, so a full table can be the best. So the question is can indexes help here?
    Furthermore there is the full table scan on POSITION:
    TABLE ACCESS FULL     Object owner=MARS     Object name=POSITION     Cost=13995     Cardinality=3854299     Bytes=150317661This looks also a large tabel (3 million + records), so is it possible to get this part smaller?
    Herald ten Dam
    http://htendam.wordpress.com

Maybe you are looking for