Outer join without outer join

I'm trying to do is to learn how to do an outer join without specifying the outer join complete, right or left. Why? For most of the reasons for performance and gain a better understanding of the Oracle.
Thank you

Charles.

Another option would be a scalar subquery in the select part, as:

SQL> select * from t;

        ID DESCR
---------- ----------
         1 T One
         2 T Two
         3 T Three

SQL> select * from t1;

        ID DESCR
---------- ----------
         1 T1 One
         2 T1 Two

SQL> select t.*, t1.descr t1_descr
  2  from t
  3     left join t1
  4        on t.id = t1.id;

        ID DESCR      T1_DESCR
---------- ---------- ----------
         1 T One      T1 One
         2 T Two      T1 Two
         3 T Three

SQL> select t.*, (select t1.descr
  2               from t1
  3               where t.id = t1.id) t1_descr
  4  from t;

        ID DESCR      T1_DESCR
---------- ---------- ----------
         1 T One      T1 One
         2 T Two      T1 Two
         3 T Three

This can be faster if the correlated T1 column is indexed, and there is a "large" number of records in t which do not correspond with t1.

John

Tags: Database

Similar Questions

  • full outer join: how to get without null values?

    full outer join: how to get without null values?

    Hello

    Please go well this url

    http://asktom.Oracle.com/pls/asktom/f?p=100:11:999478429860455:P11_QUESTION_ID:6585774577187

    Thank you
    Prakash P

  • Left outer join without data in a table

    I have two tables defined (see below). Emp table has given, and there is still no data in the table of Emp_Type! Now it is empty.

    I want to write a query that returns the data from the tables, even if there is no data in the Emp_type table. I use a left outer join but it return nothing. Can anyone help?
    create table EMP
    (
      EMPID   NUMBER(10,2),
      EMPNAME VARCHAR2(100)
    );
    
    INSERT INTO emp (empid,empname) values (1, 'Mark');
    INSERT INTO emp (empid,empname) values (2, 'Jason');
    INSERT INTO emp (empid,empname) values (3, 'Kevin');
    INSERT INTO emp (empid,empname) values (4, 'Drew');
    INSERT INTO emp (empid,empname) values (5, 'Jessica');
    INSERT INTO emp (empid,empname) values (6, 'Pena');
    INSERT INTO emp (empid,empname) values (7, 'Roxanne');
    
    create table EMP_Type
    (
      ID          NUMBER(10,2),
      EMPID       NUMBER(10,2),
      TYPE_ID     NUMBER(10,2),
      END_DATE    DATE
    );
    
    No data
    
    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;

    WHERE t.type_id = 1

    will be ever true when table has no rows (or t.type_id is NULL?)

  • Bug with an outer join, or & Analytics function (or rownum)

    Hello

    Seems to be a combination of an outer join, OR and rownum confuses the CBO.

    First request is without rownum, the second is with rownum.

    The second query expects 203 t lines and never ends. It should behave the same as query 1, with 24 M lines.

    Remove the GOLD clause query 2 allows him to behave as a query 1, with 24 M lines.

    We never saw it? Is there a solution?

    SELECT *
      FROM message i
      LEFT JOIN (SELECT hi.message_id, hi.update_dt
                   FROM message_hist hi) h ON (t.id = h.master_id
                                           AND(t.update_dt = h.update_dt OR h.update_dt <TO_DATE('150901','RRMMDD')));
          
    -----------------------------------------------------------------------------------------------                                                                                                                                                                                                              
    | Id  | Operation           | Name                    | Rows  | Bytes | Cost (%CPU)| Time     |                                                                                                                                                                                                              
    -----------------------------------------------------------------------------------------------                                                                                                                                                                                                              
    |   0 | SELECT STATEMENT    |                         |    24M|    13G|   475G  (2)|999:59:59 |                                                                                                                                                                                                              
    |   1 |  NESTED LOOPS OUTER |                         |    24M|    13G|   475G  (2)|999:59:59 |                                                                                                                                                                                                              
    |   2 |   TABLE ACCESS FULL | MESSAGE                 |  8037K|  1318M| 29883   (2)| 00:06:59 |                                                                                                                                                                                                              
    |   3 |   VIEW              |                         |     3 |  1302 | 59136   (2)| 00:13:48 |                                                                                                                                                                                                              
    |*  4 |    TABLE ACCESS FULL| MESSAGE_HIST            |     3 |   168 | 59136   (2)| 00:13:48 |                                                                                                                                                                                                              
    -----------------------------------------------------------------------------------------------                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                 
    Predicate Information (identified by operation id):                                                                                                                                                                                                                                                          
    ---------------------------------------------------                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                                                 
       4 - filter("I"."MESSAGE_ID"="HI"."MESSAGE_ID" AND                                                                                                                                                                                                                                                         
                  ("HI"."UPDATE_DT"<TO_DATE('150901','RRMMDD') OR "I"."UPDATE_DT"="HI"."UPDATE_DT"))     
    ----------------              
    SELECT *
      FROM message i
      LEFT JOIN (SELECT hi.message_id, hi.update_dt
                      , ROWNUM
                   FROM message_hist hi) h ON (t.id = h.master_id
                                           AND(t.update_dt = h.update_dt OR h.update_dt <TO_DATE('150901','RRMMDD')));
         
    -------------------------------------------------------------------------------------------------                                                                                                                                                                                                            
    | Id  | Operation             | Name                    | Rows  | Bytes | Cost (%CPU)| Time     |                                                                                                                                                                                                            
    -------------------------------------------------------------------------------------------------                                                                                                                                                                                                            
    |   0 | SELECT STATEMENT      |                         |   203T|   112P|   475G  (2)|999:59:59 |                                                                                                                                                                                                            
    |   1 |  NESTED LOOPS OUTER   |                         |   203T|   112P|   475G  (2)|999:59:59 |                                                                                                                                                                                                            
    |   2 |   TABLE ACCESS FULL   | MESSAGE                 |  8037K|  1318M| 29883   (2)| 00:06:59 |                                                                                                                                                                                                            
    |   3 |   VIEW                |                         |    25M|    10G| 59151   (2)| 00:13:49 |                                                                                                                                                                                                            
    |*  4 |    VIEW               |                         |    25M|    10G| 59151   (2)| 00:13:49 |                                                                                                                                                                                                            
    |   5 |     COUNT             |                         |       |       |            |          |                                                                                                                                                                                                            
    |   6 |      TABLE ACCESS FULL| MESSAGE_HIST            |    25M|  1355M| 59151   (2)| 00:13:49 |                                                                                                                                                                                                            
    -------------------------------------------------------------------------------------------------                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                                                                 
    Predicate Information (identified by operation id):                                                                                                                                                                                                                                                          
    ---------------------------------------------------                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                                                 
       4 - filter("I"."MESSAGE_ID"="H"."MESSAGE_ID" AND ("I"."UPDATE_DT"="H"."UPDATE_DT" OR                                                                                                                                                                                                                          
                  "H"."UPDATE_DT"<TO_DATE('150901','RRMMDD')))         
     
    

    RowNum in a subquery is supposed to ensure that the subquery is evaluated completely before filtering, otherwise, how could you go out rownum?

    Your question is compounded because of the join condition that forces a level of nested loops, which means that the table should be fully analysed once for each line of conduct rowsource. You can either transform the join in an equijoin and allow a hash to run, or you join could materialize the subquery once.

    Allow the hash join:

    SELECT count (*)

    Message FROM

    LEFT JOIN (SELECT hi.message_id, hi.update_dt

    ROWNUM

    OF message_hist salvation) PM ON (i.message_id = h.message_id

    AND i.update_dt = h.update_dt)

    LEFT JOIN (SELECT hi.message_id, hi.update_dt

    ROWNUM

    OF message_hist salvation) h2 ON (i.message_id = h2.message_id

    AND h2.update_dt<>

    AND h2.update_dt <> i.update_dt)

    /

    ----------------------------------------------------------------------------------------

    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |

    ----------------------------------------------------------------------------------------

    |   0 | SELECT STATEMENT |              |     1.    66.   211 (1) | 00:00:01 |

    |   1.  GLOBAL TRI |              |     1.    66.            |          |

    |*  2 |   EXTERNAL RIGHT HASH JOIN |              |   800 | 52800 |   211 (1) | 00:00:01 |

    |*  3 |    VIEW                 |              |     1.    22.    70 (0) | 00:00:01 |

    |   4.     COUNTY |              |       |       |            |          |

    |   5.      TABLE ACCESS FULL | MESSAGE_HIST |     1.    22.    70 (0) | 00:00:01 |

    |*  6 |    EXTERNAL RIGHT HASH JOIN |              |   800 | 35200.   141 (1) | 00:00:01 |

    |   7.     VIEW                |              |     1.    22.    70 (0) | 00:00:01 |

    |   8.      COUNTY |              |       |       |            |          |

    |   9.       TABLE ACCESS FULL | MESSAGE_HIST |     1.    22.    70 (0) | 00:00:01 |

    |  10.     TABLE ACCESS FULL | MESSAGE |   800 | 17600 |    70 (0) | 00:00:01 |

    ----------------------------------------------------------------------------------------

    Information of predicates (identified by the operation identity card):

    ---------------------------------------------------

    2 - access("I".") MESSAGE_ID '= 'H2'.' MESSAGE_ID "(+))"

    filter ("H2". "UPDATE_DT" (+)<>'I'. " ("' UPDATE_DT")

    3 - filter("H2".") UPDATE_DT "(+)<>

    6 - access("I".") "UPDATE_DT" ="H" UPDATE_DT "(+) AND"

    "I"." ' MESSAGE_ID ' ="H" MESSAGE_ID "(+))"

    Materialize the subquery:

    WITH h AS (SELECT / * + MATERIALIZE * / hi.message_id, hi.update_dt)

    ROWNUM

    OF message_hist salvation)

    SELECT count (*)

    Message FROM

    LEFT JOIN: ON (i.message_id = h.message_id

    AND (i.update_dt = h.update_dt OR h.update_dt<>

    ----------------------------------------------------------------------------------------------------------

    | ID | Operation | Name                        | Lines | Bytes | Cost (% CPU). Time |

    ----------------------------------------------------------------------------------------------------------

    |   0 | SELECT STATEMENT |                             |     1.    22.  1740 (0) | 00:00:01 |

    |   1.  TRANSFORMATION OF THE TEMPORARY TABLE.                             |       |       |            |       |

    |   2.   LOAD SELECT ACE | SYS_TEMP_0FD9D6810_5B8F6E67 |       |       |            |       |

    |   3.    COUNT                   |                             |       |       |            |       |

    |   4.     TABLE ACCESS FULL | MESSAGE_HIST |     1.    22.    70 (0) | 00:00:01 |

    |   5.   GLOBAL TRI |                             |     1.    22.            |       |

    |   6.    NESTED EXTERNAL LOOPS |                             |   800 | 17600 |  1670 (0) | 00:00:01 |

    |   7.     TABLE ACCESS FULL | MESSAGE |   800 | 17600 |    70 (0) | 00:00:01 |

    |   8.     VIEW                   |                             |     1.       |     2 (0) | 00:00:01 |

    |*  9 |      VIEW                  |                             |     1.    22.     2 (0) | 00:00:01 |

    |  10.       TABLE ACCESS FULL | SYS_TEMP_0FD9D6810_5B8F6E67 |     1.    22.     2 (0) | 00:00:01 |

    ----------------------------------------------------------------------------------------------------------

    Information of predicates (identified by the operation identity card):

    ---------------------------------------------------

    9 - filter("I".") ' MESSAGE_ID ' ="H" MESSAGE_ID' AND ('I'. "" "UPDATE_DT"="H" UPDATE_DT' OR

    "H"." UPDATE_DT ".<>

    You may need to change the first condition to make sure that you select the correct subquery.

    -edit

    Not able to view a plan but you can invade the second join condition select and then the result of a subquery with a predicate according to your requirement. This should delay the or rating and leave only an equijoin (although rowsource return may be slightly larger than the opposite).

    -Second edition, it did not work exactly when I tried it.

    A hybrid of the previous two plans with a slight modification of how he was imitating the GOLD:

    WITH h AS (SELECT / * + MATERIALIZE * / hi.message_id, hi.update_dt)

    ROWNUM Clotilde

    OF message_hist salvation)

    SELECT i.MESSAGE_ID

    i.UPDATE_DT

    COALESCE(h.message_id,h2.message_id) message_id

    , COALESCE (h.update_dt, h2.update_dt) update_dt

    Clotilde COALESCE (h.rown, h2.rown)

    Message FROM

    LEFT JOIN: ON (i.message_id = h.message_id

    AND i.update_dt = h.update_dt)

    LEFT JOIN: h2 WE (DECODE(h.message_id,,i.message_id) = h2.message_id - only try this if previous join returned NULL

    AND h2.update_dt<>

    /

    --------------------------------------------------------------------------------------------------------
    | ID | Operation | Name                      | Lines | Bytes | Cost (% CPU). Time |
    --------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT |                           |     1.    66.     8 (0) | 00:00:01 |
    |   1.  TRANSFORMATION OF THE TEMPORARY TABLE.                           |       |       |            |          |
    |   2.   LOAD SELECT ACE | SYS_TEMP_0FD9D6605_28F27F |       |       |            |          |
    |   3.    COUNT                   |                           |       |       |            |          |
    |   4.     TABLE ACCESS FULL | MESSAGE_HIST |   150.  3300 |     2 (0) | 00:00:01 |
    |   5.   GLOBAL TRI |                           |     1.    66.            |          |
    |*  6 |    EXTERNAL RIGHT HASH JOIN |                           | 10497.   676K |     6 (0). 00:00:01 |
    |*  7 |     VIEW                   |                           |   150.  3300 |     2 (0) | 00:00:01 |
    |   8.      TABLE ACCESS FULL | SYS_TEMP_0FD9D6605_28F27F |   150.  3300 |     2 (0) | 00:00:01 |
    |*  9 |     OUTER HASH JOIN |                           |   328. 14432 |     4 (0) | 00:00:01 |
    |  10.      TABLE ACCESS FULL | MESSAGE |   200 |  4400 |     2 (0) | 00:00:01 |
    |  11.      VIEW                  |                           |   150.  3300 |     2 (0) | 00:00:01 |
    |  12.       TABLE ACCESS FULL | SYS_TEMP_0FD9D6605_28F27F |   150.  3300 |     2 (0) | 00:00:01 |
    --------------------------------------------------------------------------------------------------------

    Information of predicates (identified by the operation identity card):
    ---------------------------------------------------

    6 - access("H2".") MESSAGE_ID "(+) = DECODE (TO_CHAR ('H'". "))" MESSAGE_ID"), NULL, 'I '. (("' MESSAGE_ID '))
    7 - filter("H2".") UPDATE_DT "(+)<>
    9 - access("I".") "UPDATE_DT" ="H" UPDATE_DT "(+) AND 'I'." "" ' MESSAGE_ID '="H" MESSAGE_ID "(+))"

    (This plan is another system if costs are not comparable)

  • Left Outer Join DR.

    Hi Experts,

    I have a requirement that says - see the chart for the past 10 days, regardless the presence data table in fact.
    Lets consider an example - Time_dim product, are my dimension tables, Purchase_Order is my fact table.

    I did it for external Purchase_Order in left RPD with TIME_DIM and inner join with the PRODUCT table.  and execution of query of exit-
    Select T.Date, P.item, count (distinct PO.order_no)
    TIME_DIM t, PRODUCT P, PURCHASE_ORDER PO
    where T.date_key = PO.date_key
    and P.item = in. agenda
    and P.item = 'laptop ';

    The query generated by OBIEE left outer join, but when the condition P.item = "Notebook" included in the query, and if there are no orders for this product in one of the date, that date will not come in the result set.

    the query to be generated by the OBIEE is-


    Select T.Date, PO.item, count (distinct PO.order_no)
    TIME_DIM t,.
    (SELECT P.ITEM, IN. ORDER_NO
    PRODUCT P, PO PURCHASE_ORDER
    WHERE P.item = in. agenda
    and P.item = 'Laptop') IN.
    WHERE T.date_key = PO.date_key (+);

    How to design the RPD to achieve this. All pray to advise on this. Thanks in advance.

    Thank you
    Chantal

    Hello

    You are on 11.1.1.7?

    I would say that your condition can be made without using external and maintenance of product and the standard between the FACT dimension, time inner join join.

    If you enable your property analysis OBIEE "Include Null values" will automatically return all the elements of time and product matching your filter (so you'll need to add a filter on 'Date' to limit it to the last 10 days or you will have a unique day of your time dimension).

    If you filter then on "Laptop", even if there is not a single value in order for "Laptop" in the last 10 days, he will be there on the screen.

    Easy, clean and you keep your inner join between the facts and Dimensions.

    Take a look at this example, I just did on SampleApp 406:

    Selection of 12 months (year 2010) and a customer (id = 89) and income. The model has only an inner join. I activate the option "Include Null values" and here is the result.

    A line with cells only empty because there is not a single revenue for customer 89 in 2010. This is exactly your condition.

    Honestly, do not touch your model using the outer join, you will have more side effects than benefits. Every single scan will do the outer join and you'll have a lot of data 'empty' return of the DB (more large data set containing just the null values) and probably you need the outer join in 15 to 25% of your analysis.

    Keep things simple, it will be faster and easier to maintain.

  • use an outer join in RowMatch

    Hello world

    I have an Obj from view to both entities like this:

    SELECT t1.rowno, t2.type

    OF table_ t1, t2 from table_2

    WHERE t1.rowno (+) = t2.rowno

    and t1.userId (+) =: bindVar

    table_1 (Rowno, UserID)

    table_2 (Rowno, type)

    I have a table on this view of Obj on my page, when I add a new line of this view Obj, this line showed in the table while he should not appear (depending on where the view clause Obj).

    according to this post https://forums.oracle.com/thread/2576480 I can use RowMatch, but here I don't know how to use an outer join in RowMatch.


    Habib


    Post edited by: Habib.Eslami

    I guess that joy cannot use matching line in this case as it only lines matching already in memory, but without an outer join. This must be done before.

    What you can try is to build the sql criteria yourself and add it to the query.  An example on how to do this at http://wp.me/pcBZk-5O

    The example shows how to add a sql custom as a criterion.

    Timo

  • Can join a Cluster of storage disk out of Maintenance DTS Mode to set up the profiles for a virtual machine storage policies?...

    Can join a Cluster of storage disk out of Maintenance DTS Mode to set up the profiles for a virtual machine storage policies?...


    IE can you define the rules of affinity DTS depending on how the rules of storage of profiles are configured for a virtual machine?

    In my mind it seems there is disconnect from the DTS and storage profiles.

    Thank you.

    = NOTE =.

    My lab at home, 2 organizes running ESXi 5.0

    Dv01 has

    Of startup vmfs 7200 RPM 160 G = dv01-BOOT

    Vmfs 1 TB 7200 RPM = VM02-VMFS

    VM02 has

    Of startup vmfs 7200 RPM 160 G = VM02-BOOT

    Vmfs 1 TB 7200 RPM = VM02-VMFS

    Vmfs 5900 RPM 2 TB = VM02-TV01

    I have (3) facility profiles of storage using 'User-defined storage Capablity' as shown below:

    (160 @ 7200 RPM SATA) boot > Boot

    Fast (160 7200 RPM SATA and 1 TB @ 7200 RPM SATA) > fast

    Slow (2 TB @ 5900 RPM SATA) > slow

    Then, I set up a storage Cluster with my local disks on dv01 (only to date)

    LocalVM disc dv01-BOOT and dv01-VMFS disk of the 'cluster of storage.

    I have a computer virtual called DC01 (HardDisk1) want to live on 'Boot' profile storage drive
    His "Non-compliant" poster according to the storage profile, it should run on drive 'boot' on dv01

    To get to this point, I put the StorageCluster in Mode of Maintenace 'DTS' and forced a sVmotion of all virtual machines off dv01-BOOT

    No disks are IO or claim of space.

    But once I take the 'DTS Maintenacne mode' STARTUP dv01 floppy is now get the DTS to return him to satisfy the storage profile (rule) I install... IE do the 'storage profile' VM complient (without doing a few externall API, the PS script or the 3rd party software calls)... ??

    Seems weird it is (or may be) such disconnection of a memory of the profiles and the StorageClusters and the DTS?

    Thank you...

    At this point, I think that storage DRS and storage profiles are two technologies to separate and work independently, but what you suggest is a great idea-

  • After careful consideration, today I decided to join Adobe Photoshop CC only to find out that it is not available to me that my laptop has Windows Vista.  What are my options other than having to buy a new computer or an older version like Ps5 or 6?

    After careful consideration, today I decided to join Adobe Photoshop CC only to find out that it is not available to me that my laptop has Windows Vista.  What are my options other than having to buy a new computer or an older version like Ps5 or 6?

    1 can't read on a Windows "upgrade version" which, in my experience, does NOT require you to format your drive... updated on what you have, without disturbing programs installed... at least that's what happened the ONLY time wherever I installed an upgrade version, so I can't give a 100% guarantee that it will work with your computer in this way... search link for all the things Microsoft http://search.microsoft.com/search.aspx?mkt=en-US&setlang=en-US

    2 - depending on the hardware you have, you may not be able to run programs CC well, or not at all

    3 CS6 is 3 years and is the ONLY non - CC version always sold... unless you can find a "legal" somewhere CS5

    Old or used software http://www.emsps.com/oldtools/

    http://forums.Adobe.com/message/1636890 warns of a purchase on eBay

  • need help with outer join filter.

    Need a little help to filter a result set and I can't seem to find a good way to do this.
    /*table*/
    
    create table invoice( farinvc_invh_code varchar2(100),
                                  farinvc_item varchar2(100),
                                  farinvc_po varchar2(100)
                                  )
       create table po( 
            supplier_number varchar2(60),
            supplier_invoice_no varchar2(60),
            po_number varchar2(60),
            run_date varchar2(60),
            PO_LINE_NUMBER varchar2(60) );
    /*data*/
    
    INSERT INTO "INVOICE" (FARINVC_INVH_CODE, FARINVC_ITEM, FARINVC_PO_ITEM) VALUES ('I0554164', '1', 'P0142245');
    INSERT INTO "INVOICE" (FARINVC_INVH_CODE, FARINVC_ITEM, FARINVC_PO_ITEM) VALUES ('I0554164', '3', 'P0142245');
    INSERT INTO "INVOICE" (FARINVC_INVH_CODE, FARINVC_ITEM, FARINVC_PO) VALUES ('I0554165', '1', 'P0142246');
    INSERT INTO "INVOICE" (FARINVC_INVH_CODE, FARINVC_ITEM, FARINVC_PO) VALUES ('I0554165', '2', 'P0142246');
    
    
    
    
    
    INSERT INTO "PO" (SUPPLIER_NUMBER, SUPPLIER_INVOICE_NO, PO_NUMBER, RUN_DATE, PO_LINE_NUMBER) VALUES ('914100121', '529132260', 'P0142245', '21-NOV-12', '1');
    INSERT INTO "PO" (SUPPLIER_NUMBER, SUPPLIER_INVOICE_NO, PO_NUMBER, RUN_DATE, PO_LINE_NUMBER) VALUES ('914100121', '529137831', 'P0142245', '21-NOV-12', '3');
    INSERT INTO "PO" (SUPPLIER_NUMBER, SUPPLIER_INVOICE_NO, PO_NUMBER, RUN_DATE, PO_LINE_NUMBER) VALUES ('914100121', '529137831', 'P0142245', '21-NOV-12', '2');
    INSERT INTO "PO" (SUPPLIER_NUMBER, SUPPLIER_INVOICE_NO, PO_NUMBER, RUN_DATE, PO_LINE_NUMBER) VALUES ('914100122', '145678', 'P0142246', '22-NOV-12', '1');
    INSERT INTO "PO" (SUPPLIER_NUMBER, SUPPLIER_INVOICE_NO, PO_NUMBER, RUN_DATE, PO_LINE_NUMBER) VALUES ('914100122', '145679', 'P0142246', '22-NOV-12', '2');
    query execution of im.

    SELECT  farinvc_invh_code,
                    supplier_number,
                    supplier_invoice_no,
                    farinvc_item, 
                    farinvc_po ,
                    po_number,
                    run_date,
                    PO_LINE_NUMBER
            FROM INVOICE, PO
            WHERE PO_NUMBER = FARINVC_PO(+)
            AND FARINVC_ITEM(+) = PO_LINE_NUMBER
            
    result
    "FARINVC_INVH_CODE"           "SUPPLIER_NUMBER"             "SUPPLIER_INVOICE_NO"         "FARINVC_ITEM"                "FARINVC_PO"                  "PO_NUMBER"                   "RUN_DATE"                    "PO_LINE_NUMBER"              
    "I0554165"                    "914100122"                   "145678"                      "1"                           "P0142246"                    "P0142246"                    "22-NOV-12"                   "1"                           
    "I0554165"                    "914100122"                   "145679"                      "2"                           "P0142246"                    "P0142246"                    "22-NOV-12"                   "2"                           
    "I0554164"                    "914100121"                   "529132260"                   "1"                           "P0142245"                    "P0142245"                    "21-NOV-12"                   "1"                           
    "I0554164"                    "914100121"                   "529137831"                   "3"                           "P0142245"                    "P0142245"                    "21-NOV-12"                   "3"                           
    ""                            "914100121"                   "529137831"                   ""                            ""                            "P0142245"                    "21-NOV-12"                   "2"                           
    It is a much larger table, and I took an excerpt in order to keep things clear and understanding. I would like to filter the result set to only show lines that have po numbers are the same and line are the same but there is an additional element. in other words as such.
    "FARINVC_INVH_CODE"           "SUPPLIER_NUMBER"             "SUPPLIER_INVOICE_NO"         "FARINVC_ITEM"                "FARINVC_PO"                  "PO_NUMBER"                   "RUN_DATE"                    "PO_LINE_NUMBER"              
    "I0554164"                    "914100121"                   "529132260"                   "1"                           "P0142245"                    "P0142245"                    "21-NOV-12"                   "1"                           
    "I0554164"                    "914100121"                   "529137831"                   "3"                           "P0142245"                    "P0142245"                    "21-NOV-12"                   "3"                           
    ""                            "914100121"                   "529137831"                   ""                            ""                            "P0142245"                    "21-NOV-12"                   "2"                           

    Hello

    Let me assure you that I understand.
    Last time, we were looking for the PO_NUMBERs who have been partially put into correspondence , i.e. groups of rows in the order table with the same po_number, which some had corresponding lines in the table Bill, and some of whom have not. It was essential that there is at least 1 line and 1 row without connections with the same purchase order.
    Now that you are interested SUPPLIER_INVOICE_NOs who are partially paired, i.e. groups of rows in the table of po with the same po_number and supplier_invoice_no, some of which have corresponding lines in the invoice table, and some are not. ("Supplier_Invoice_No" is quite a mouthful. "We'll abbreviate as sin in the future.) However, the final selection is based on po_numbers: If a po_number has partially matched sins, then we are interested all po_number. For example, the result set must include = 529132260 SIN, even if that sin is completely, because there is a partially matching sin (529137831) with the same po_number (P0142245).

    As this problem revolves around partially matching sins, let's call them Cardinal sins . We can calculate match_cnt and total_cnt based NAS as well as po_number. Then, we can use another analytic function so see if the po_number has all cardinal_sins, like this:

    WITH    joined_data     AS
    (
         SELECT     i.farinvc_invh_code
         ,     p.supplier_number
         ,     p.supplier_invoice_no
         ,     i.farinvc_item
         ,     i.farinvc_po
         ,     p.po_number
         ,     p.run_date
         ,     p.po_line_number
         ,     COUNT (i.farinvc_po) OVER ( PARTITION BY  p.po_number
                                            ,                  p.supplier_invoice_no
                               )     AS match_cnt
         ,     COUNT (*)           OVER ( PARTITION BY  p.po_number
                                            ,                  p.supplier_invoice_no
                                          )     AS total_cnt
         FROM           po       p
         LEFT OUTER JOIN  invoice  i  ON   i.farinvc_po    = p.po_number
                                      AND  i.farinvc_item  = p.po_line_number
    )
    ,     got_cardinal_sin_cnt     AS
    (
         SELECT  joined_data.*
         ,     SUM ( CASE
                        WHEN  match_cnt  >= 1
                     AND     match_cnt  <  total_cnt
                     THEN  1
                    END
                  ) OVER (PARTITION BY  po_number)     AS cardinal_sin_cnt
         FROM    joined_data
    )
    SELECT    farinvc_invh_code
    ,       supplier_number
    ,       supplier_invoice_no
    ,       farinvc_item
    ,       farinvc_po
    ,       po_number
    ,       run_date
    ,       po_line_number
    FROM       got_cardinal_sin_cnt
    WHERE       cardinal_sin_cnt     > 0
    ORDER BY  po_number
    ,            farinvc_item
    ;
    
  • How do the query select outer join to a report of the APEX

    Hi all

    I'm Ann.

    I have a select statement that is used to calculate statistics for a month (October 2012 in this example)
    Select ph.phase_number
    sum ((case
    WHEN ph.date_finished IS NULL or ph.date_finished > last_day (TO_DATE (' ' Oct 2012 ', ' MY YYYY' "))
    THEN last_day (TO_DATE (' ' Oct 2012 ', ' MY YYYY' "))
    Of OTHER ph.date_finished
    END)
    (-ph.date_started + 1) / count (def.def_id) as avg_days
    Ph phase_membership
    inner join court_engagement this on ph.mpm_eng_id = ce.engagement_id
    join in-house defendant def on ce.defendant_id = def.def_id
    where def.active = 1
    and ph.date_started < = last_day (TO_DATE (' ' Oct 2012 ', ' MY YYYY' "))
    and ph.active = 1
    and UPPER (ce.court_name) LIKE '% '.
    Rollup Group (phase_number)
    ;

    The result is as below
    Phase_Number AVG_DAYS
    Phase One 8.6666666666666667
    Phase two 14.6
    Phase three 12
    11.4615365

    I have another list of selection mainly the list of months between two date value.
    Select to_char (which_month, 'LUN YYYY') as display_month
    de)
    Select add_months (to_date (' ' August 2012 ', ' MY YYYY' "), rownum-1) which_month
    of object
    where
    rownum < = months_between (to_date (' ' Oct 2012 ', ' MY YYYY' "), add_months (to_date (' ' August 2012", "MY YYYY"), - 1))
    order of which_month)

    The query result is as below

    DISPLAY_MONTH

    AUGUST 2012
    SEP 2012
    OCT 2012

    Is it possible I can join these two select statement above to generate a comparable result:

    Days of month Phase number Avg
    August 2012 Phase One 8.666
    Sep 2012 Phase One 7.66
    Oct 2012 Phase One 5,66
    August 2012 Phase two 8.666
    Sep 2012 Phase two 7.66
    Oct 2012 Phase two 5,66
    August 2012 Phase three 8.666
    Sep 2012 Phase three 7.66
    Oct 2012 Phase three 5,66

    Or
    Days of month Phase number Avg
    August 2012 Phase One 8.666
    August 2012 Phase two 7.66
    August 2012 Phase three 5,66
    Sep 2012 Phase One 8.666
    Sep 2012 Phase two 7.66
    Sep 2012 Phase three 5,66
    Oct 2012 Phase One 8.666
    Oct 2012 Phase two 7.66
    Oct 2012 Phase three 5,66

    And it can be controlled by Phase number or month.
    My other colleague suggested I should use a left outer join, but after having tried many ways, I'm still stuck.

    I tried select is
    Select a.display_month, b.* in)
    Select to_char (which_month, 'LUN YYYY') as display_month
    de)
    Select add_months (to_date (' ' August 2012 ', ' MY YYYY' "), rownum-1) which_month
    of object
    where
    rownum < = months_between (to_date (' ' Oct 2012 ', ' MY YYYY' "), add_months (to_date (' ' August 2012", "MY YYYY"), - 1))
    order which_month)) a left outer join

    (Select to_char (ph.date_finished, 'MY YYYY') as join_month, ph.phase_number)
    sum ((case
    WHEN ph.date_finished IS NULL or ph.date_finished > last_day (TO_DATE (a.display_month, 'MY YYYY'))
    THEN last_day (TO_DATE (a.display_month, 'MY YYYY'))
    Of OTHER ph.date_finished
    END)
    (-ph.date_started + 1) / count (def.def_id) as avg_days
    Ph phase_membership
    inner join court_engagement this on ph.mpm_eng_id = ce.engagement_id
    join in-house defendant def on ce.defendant_id = def.def_id
    where def.active = 1
    and ph.date_started < = last_day (TO_DATE (a.display_month, 'MY YYYY'))
    and ph.active = 1
    and UPPER (ce.court_name) LIKE '% '.
    To_char (ph.date_finished, 'MY YYYY'), group (phase_number) rollup) b
    On a.display_month = b.join_month

    but then I get an error
    SQL error: ORA-00904: "A." "" DISPLAY_MONTH ": invalid identifier

    I need to view a report on the APEX with option for people to download at least format CSV.
    Already 1 inteactive report in the page, so I don't think adds another interactive report without using the iframe trick.

    If any of you have any ideas, please help.

    Thank you very much.

    Ann

    Hello Ann,.

    Frank has done a very good job. I am also impressed.

    Is in regard to your correction to his question, the problem is on this replacement you did

    last_day(TO_DATE(am.which_month,'MON YYYY'))
    

    AM.which_month is already a date type, and you don't need to convert it to this day.
    Here is the correct way:

    last_day(am.which_month)
    

    There are also sometimes with the data you've posted have no line for this month. So I also added a function NVL to display 0 under avg_days for these cases.

    Here is my corrected query:

    DEFINE startmonth = "Aug 2012";
    DEFINE endmonth   = "Oct 2012";
    WITH  all_months  AS
    (
       SELECT ADD_MONTHS(to_date('&startmonth','MON YYYY'), ROWNUM-1) AS which_month
       ,      ADD_MONTHS(to_date('&startmonth','MON YYYY'), ROWNUM  ) AS next_month
       from all_objects
       where
       rownum <= months_between(to_date('&endmonth','MON YYYY'), add_months(to_date('&startmonth','MON YYYY'), -1))
    )
    SELECT TO_CHAR (am.which_month, 'Mon YYYY')  AS month
         , ph.phase_number
         , NVL(sum ( (CASE
                     WHEN ph.date_finished IS NULL OR ph.date_finished > last_day(am.which_month)
                     THEN last_day(am.which_month)
                     ELSE ph.date_finished
                  END
                 ) - ph.date_started + 1
               ) / count(def.def_id), 0) as avg_days
      FROM all_months am
           LEFT OUTER JOIN  a_phase_membership  ph  PARTITION BY (ph.phase_number)
              ON  am.which_month <= ph.date_started
              AND am.next_month  >  ph.date_started
              AND ph.date_started <= last_day(am.which_month)  -- May not be needed
              AND ph.active = 1
           LEFT OUTER JOIN  a_engagement  ce
              ON  ph.mpm_eng_id = ce.engagement_id
              AND ce.court_name IS NOT NULL  -- or something involving LIKE
           LEFT OUTER join  a_defendant     def
              ON  ce.defendant_id = def.def_id
              AND def.active = 1
     GROUP BY ROLLUP(phase_number, am.which_month)
     ORDER BY  am.which_month
            ,  ph.phase_number
    ;
    
    The output is:
    MONTH    PHASE_NUMBER           AVG_DAYS
    -------- -------------------- ----------
    Aug 2012 PHASE ONE                     0
    Aug 2012 PHASE THREE                   0
    Aug 2012 PHASE TWO                     0
    Sep 2012 PHASE ONE                    12
    Sep 2012 PHASE THREE                   1
    Sep 2012 PHASE TWO                     9
    Oct 2012 PHASE ONE                     8
    Oct 2012 PHASE THREE                   0
    Oct 2012 PHASE TWO                    14
             PHASE ONE                    11
             PHASE THREE                   1
             PHASE TWO                  11.5
                                  9.71428571
    

    I don't know if that's really what you want. In the case check it and let me know.

    Kind regards.
    Al

  • Outer join with Oracle syntax

    Hi, I am new to oracle and I worked this request for reports for about 2 weeks, please take a look at my request
    SELECT mmt.transaction_date "Transaction Date", 
                msib.segment1 "Item", 
                gcc.segment1||'-'||gcc.segment2||'-'||gcc.segment3||'-'||gcc.segment4||'-'||gcc.segment5||'-'||gcc.segment6||'-'||(nvl(gcc.segment7,'000000')) "account",
                (CASE mttype.transaction_type_name
                WHEN 'Average cost update' THEN
              ((nvl(mmt.new_cost,0) - nvl(mmt.prior_cost,0)) * nvl(mmt.quantity_adjusted,0)) + nvl(mmt.variance_amount,0)
                ELSE
                 (mmt.Primary_quantity * nvl(mmt.actual_cost, 0) + nvl(mmt.variance_amount, 0))
               END) "Transaction Value",
                mttype.description "Transaction Type",
                mmt.subinventory_code "Subinventory",
                ood.organization_code "Org",
                msib.Primary_UOM_Code "UOM",
                mmt.Primary_Quantity "Primary Quantity",
                mtr.description "Reason",
                mmt.transaction_reference "Reference"
    FROM mtl_material_transactions mmt,
             mtl_system_items_b msib,
             mtl_transaction_accounts mta,
             gl_code_combinations gcc,
             mtl_transaction_types mttype,
             Org_Organization_Definitions ood,
             mtl_transaction_reasons mtr
    WHERE mmt.transaction_date >= :P_DATE_FROM 
               and mmt.transaction_date  < :P_DATE_TO +1
               and mmt.organization_id = :P_ORGANIZATION 
               and msib.organization_ID = mmt.organization_ID  
               and msib.inventory_item_id=mmt.inventory_item_id 
               and mta.transaction_id=mmt.transaction_id
               and gcc.code_combination_id = mta.reference_account
               and mttype.transaction_type_id=mmt.transaction_type_id
               and mmt.reason_id=mtr.reason_id(+)
               and ood.organization_id=mmt.organization_id
               and mttype.transaction_type_id = :P_TRANSACTION_TYPE
               and msib.segment1 = :P_ITEM
               AND gcc.segment2 = :P_ACCOUNT
    null values is on the mtl_material_transactions table, which is reason_id, subinventory_code and transaction_reference
    put desired option on would show all archives on mtl_material_transactions with null values
    so I put the symbol of the outer join right?
    BTW
    I tried to put the (+) sign on various locations but it still not good and I am really at a loss

    Hello

    Whenever you have any questions, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and the desired results from these data. I know that's not always easy, but it is really necessary. Compounds that, I do not understand your problem.
    It could be useful that simplify you the problem. If you were not interested in, say, the mta, gcc, tables msib and ood, would you still have the same problem? If so, forget all these tables and just after, CREATE TABLE and INSERT statements for the remaining tables and the results you want from this data.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.

    The query you posted will not exclude any line of mmt just because it doesn't have a corresponding line in the mtr; That's what the condition:

    and mmt.reason_id=mtr.reason_id(+)
    

    but it will exclude mmt lines if they do not have matching rows in other tables. Maybe you need + plus join and may under certain conditions non-join, such as conditions

    gcc.segment2 (+) = :P_ACCOUNT
    

    Too much. It's just a guess. Without seeing your sample data and the correct results, you should get from this data, I can't say.

  • Different Outer Join query result

    Hi all

    Under query gives the expected result


    Select DECODE (FPOVR. PROFILE_OPTION_VALUE,
    NULL, FPOVS. PROFILE_OPTION_VALUE, FPOVR. ZZ PROFILE_OPTION_VALUE)
    OPS FND_PROFILE_OPTIONS, FND_PROFILE_OPTION_VALUES FPOVR,.
    FND_PROFILE_OPTION_VALUES FPOVS where 1 = 1 and FPOVS. LEVEL_ID (+) = 10001
    and FPOVS. LEVEL_VALUE (+) = 0
    and FPOVS. PROFILE_OPTION_ID (+) IS FRENCH POLYNESIA. PROFILE_OPTION_ID
    and FPOVR. (+) LEVEL_ID = 10003 and FPOVR. LEVEL_VALUE (+) = 21533
    and FPOVR. PROFILE_OPTION_ID (+) IS FRENCH POLYNESIA. PROFILE_OPTION_ID
    and fpo.profile_option_name = 'GL_SET_OF_BKS_ID. '


    But the following query does not give the expected result.


    Select DECODE (FPOVR. PROFILE_OPTION_VALUE,
    NULL, FPOVS. PROFILE_OPTION_VALUE, FPOVR. ZZ PROFILE_OPTION_VALUE)
    OPS FND_PROFILE_OPTIONS, FND_PROFILE_OPTION_VALUES FPOVR,.
    FND_PROFILE_OPTION_VALUES FPOVS where 1 = 1 and FPOVS. LEVEL_ID (+) = 10001
    and FPOVS. LEVEL_VALUE (+) = 0
    and FPOVS. PROFILE_OPTION_ID (+) IS FRENCH POLYNESIA. PROFILE_OPTION_ID
    and FPOVR. (+) LEVEL_ID = 10003 and FPOVR. LEVEL_VALUE = 21533
    and FPOVR. PROFILE_OPTION_ID (+) IS FRENCH POLYNESIA. PROFILE_OPTION_ID
    and fpo.profile_option_name = 'GL_SET_OF_BKS_ID. '

    Difference between them is a join with external FPOVR. LEVEL_VALUE and hard coded value. Why these query above return different results even if the outer join is made with hard coded in value?

    Thank you
    SK

    SK says:
    Hi all

    Under query gives the expected result

    Select DECODE (FPOVR. PROFILE_OPTION_VALUE,
    NULL, FPOVS. PROFILE_OPTION_VALUE, FPOVR. ZZ PROFILE_OPTION_VALUE)
    OPS FND_PROFILE_OPTIONS, FND_PROFILE_OPTION_VALUES FPOVR,.
    FND_PROFILE_OPTION_VALUES FPOVS where 1 = 1 and FPOVS. LEVEL_ID (+) = 10001
    and FPOVS. LEVEL_VALUE (+) = 0
    and FPOVS. PROFILE_OPTION_ID (+) IS FRENCH POLYNESIA. PROFILE_OPTION_ID
    and FPOVR. (+) LEVEL_ID = 10003 and FPOVR. LEVEL_VALUE (+) = 21533
    and FPOVR. PROFILE_OPTION_ID (+) IS FRENCH POLYNESIA. PROFILE_OPTION_ID
    and fpo.profile_option_name = 'GL_SET_OF_BKS_ID. '

    But the following query does not give the expected result.

    Select DECODE (FPOVR. PROFILE_OPTION_VALUE,
    NULL, FPOVS. PROFILE_OPTION_VALUE, FPOVR. ZZ PROFILE_OPTION_VALUE)
    OPS FND_PROFILE_OPTIONS, FND_PROFILE_OPTION_VALUES FPOVR,.
    FND_PROFILE_OPTION_VALUES FPOVS where 1 = 1 and FPOVS. LEVEL_ID (+) = 10001
    and FPOVS. LEVEL_VALUE (+) = 0
    and FPOVS. PROFILE_OPTION_ID (+) IS FRENCH POLYNESIA. PROFILE_OPTION_ID
    and FPOVR. (+) LEVEL_ID = 10003 and FPOVR. LEVEL_VALUE = 21533
    and FPOVR. PROFILE_OPTION_ID (+) IS FRENCH POLYNESIA. PROFILE_OPTION_ID
    and fpo.profile_option_name = 'GL_SET_OF_BKS_ID. '

    Difference between them is a join with external FPOVR. LEVEL_VALUE and hard coded value.

    In fact, the difference is that the condition relating to FPOVR. LEVEL_VALUE to 21533 is part of the outer join condition in the first query, but it is not in the second query.

    Why these query above return different results even if the outer join is made with hard coded in value?

    When you say

    FPOVR.LEVEL_VALUE(+) = 21533
    

    (with a sign +) only the lines of fpovr with level_value = 21533 will join the other table. If there is no such line in fpovr, then a row of output will be generatedd for each row in the other table anyway.
    When you say

    FPOVR.LEVEL_VALUE = 21533
    

    (without a sign +) then the outer join is made using the other conditions, which may result in some lines of the other table who appear in the result set with NULL in places where the values of fpovr would normally appear. Then when the join is complete, the condition is applied, and all these lines with the NULL value instead of fpovr.level_value are deleted because they do not meet the condition "FPOVR. LEVEL_VALUE = 21533 ". The effect is identical to an inner join.

    When you use the old rating of outer join (i.e. with signs +), if any condition involving the fpovr table has a + sign, and then all of the conditions involving table fpovr must have a + sign, otherwise the result will be the same if none of the conditions were a sign +.

  • Problem with ANSI OUTER JOIN

    Hi all

    I have issues with the help of ANSI LEFT JOIN compared to Oracle (+). Below test I did the same thing.
          create table emp (emp_id number(10), emp_name varchar2(50));
          create table courses (course_id number(10), emp_id number(10), course_name varchar2(50));
          
          INSERT INTO EMP values(1,'A');
          INSERT INTO EMP values(2,'B');
          INSERT INTO EMP values(3,'C');
    
          INSERT INTO COURSES values(1,1,'ORACLE');
          INSERT INTO COURSES values(2,1,'JAVA');
          INSERT INTO COURSES values(3,3,'C#');
    
          --*Query 1
          SELECT a.*, b.*
          FROM EMP a  LEFT JOIN COURSES b 
          ON a.emp_id = b.emp_id
          AND a.emp_name = 'A'
    
          --*Query 2      
          SELECT a.*, b.* 
          FROM EMP a, COURSES b 
          where a.emp_id = b.emp_id(+)
          and a.emp_name = 'A'
    Here Query1 return all records of 4 same records regardless of emp_name = 'A' where as Query2 returns 2 records of ep_name = 'A' which is correct.

    Is this correct? I'm confused if you use the standard ANSI OUTER JOINS or not.

    I am using Oracle 11g

    Thank you.

    Change your AND WHERE, in the style of ANSI, select:

    SELECT a.*, b.*
    FROM EMP a  LEFT JOIN COURSES b
    ON a.emp_id = b.emp_id
    WHERE a.emp_name = 'A'
    

    Filters in the clause are those who use the (+) in the Oracle syntax.
    Filters WITHOUT (+) in the Oracle syntax should be in the WHERE clause using the ANSI syntax.

    Published by: Kim Berg Hansen on September 23, 2011 08:03

  • Outer join in where clause

    Hi all
    in the following query
    select bi.SECURITY_ID, sum(r.UNREALISED_PL) UNREALISED_PL
      from XTR_REVALUATION_DETAILS r, xtr_bond_issues bi
      
    , (select x1.deal_no,x1.deal_subtype, x1.contract_code, min(x1.effective_date) min_date,max(x1.effective_date) max_date                                   
          from xtr_revaluation_details x1 
           where x1.effective_date between to_date(:p_date, 'dd.mm.yyyy') and to_date(:p_end_date, 'dd.mm.yyyy')  
           and x1.PORTFOLIO_CODE = :portfolio
           and x1.deal_type = 'BOND'
           and x1.company_code = :p_fund
           and x1.deal_subtype in ('BUY','SELL')
      group by x1.deal_no,x1.contract_code, x1.deal_subtype) i 
      where r.amount_type='UNREAL'
      and bi.BOND_ISSUE_code = r.contract_code
      AND r.DEAL_TYPE = 'BOND'
      AND r.TRANSACTION_NO=1
      and r.PORTFOLIO_CODE = :portfolio
      and r.company_code = :p_fund
      AND r.PERIOD_TO>TO_DATE(:p_date,'DD.MM.YYYY') 
      AND r.PERIOD_TO<=TO_DATE(:p_end_date,'DD.MM.YYYY')  
      and bi.AUTHORISED = 'Y'
      and r.deal_subtype in ('BUY','SELL')
      and i.deal_no = r.deal_no 
    
      and i.contract_code(+) = r.contract_code
      and i.deal_subtype(+) = r.deal_subtype
      and r.effective_date != decode (r.deal_subtype,'BUY',i.min_date,'SELL',i.max_date)
       
      GROUP BY bi.SECURITY_ID 
    I can't do something like that
    and r.effective_date != (+)decode (r.deal_subtype,'BUY',i.min_date,'SELL',i.max_date)
    How can I filter the query to show me the result in all cases? Connection between r and I should be?


    Version:
    Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production
    PL/SQL Release 9.2.0.8.0 - Production
    "CORE     9.2.0.8.0     Production"
    TNS for Linux: Version 9.2.0.8.0 - Production
    NLSRTL Version 9.2.0.8.0 - Production
    Thanks in advance,
    Alexander.

    Hello

    I think you can do this with the ansi syntax - I can't test without your structures, but I think it works...

    /* Formatted on 15/09/2011 14:05:12 (QP5 v5.163.1008.3004) */
      SELECT bi.SECURITY_ID, SUM (r.UNREALISED_PL) UNREALISED_PL
        FROM XTR_REVALUATION_DETAILS r
             JOIN xtr_bond_issues bi
                ON (bi.BOND_ISSUE_code = r.contract_code)
             LEFT OUTER JOIN (  SELECT x1.deal_no,
                                       x1.deal_subtype,
                                       x1.contract_code,
                                       MIN (x1.effective_date) min_date,
                                       MAX (x1.effective_date) max_date
                                  FROM xtr_revaluation_details x1
                                 WHERE x1.effective_date BETWEEN TO_DATE (
                                                                    :p_date,
                                                                    'dd.mm.yyyy')
                                                             AND TO_DATE (
                                                                    :p_end_date,
                                                                    'dd.mm.yyyy')
                                       AND x1.PORTFOLIO_CODE = :portfolio
                                       AND x1.deal_type = 'BOND'
                                       AND x1.company_code = :p_fund
                                       AND x1.deal_subtype IN ('BUY', 'SELL')
                              GROUP BY x1.deal_no,
                                       x1.contract_code,
                                       x1.deal_subtype) i
                ON (    i.deal_no = r.deal_no
                    AND i.contract_code = r.contract_code
                    AND i.deal_subtype = r.deal_subtype
                    AND r.effective_date !=
                           DECODE (r.deal_subtype,
                                   'BUY', i.min_date,
                                   'SELL', i.max_date))
       WHERE     r.amount_type = 'UNREAL'
             AND r.DEAL_TYPE = 'BOND'
             AND r.TRANSACTION_NO = 1
             AND r.PORTFOLIO_CODE = :portfolio
             AND r.company_code = :p_fund
             AND r.PERIOD_TO > TO_DATE (:p_date, 'DD.MM.YYYY')
             AND r.PERIOD_TO <= TO_DATE (:p_end_date, 'DD.MM.YYYY')
             AND bi.AUTHORISED = 'Y'
             AND r.deal_subtype IN ('BUY', 'SELL')
    GROUP BY bi.SECURITY_ID
    

    David

  • Problem with XMLTABLE and LEFT OUTER JOIN

    Hi all.

    I have a problem with XMLTABLE and LEFT OUTER JOIN, in 11g it returns the correct result, but in 10g it doesn't, it is illustrated as a INNER JOIN.
    SELECT * FROM v$version;
    
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    PL/SQL Release 11.2.0.1.0 - Production
    "CORE     11.2.0.1.0     Production"
    TNS for Linux: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    
    --test for 11g
    
    CREATE TABLE XML_TEST(
         ID NUMBER(2,0),
         XML XMLTYPE
    );
    
    INSERT INTO XML_TEST
    VALUES
    (
         1,
         XMLTYPE
         ('
              <msg>
                   <data>
                        <fields>
                             <id>g1</id>
                             <dat>data1</dat>
                        </fields>
                   </data>
              </msg>
         ')
    );
    
    INSERT INTO XML_TEST
    VALUES
    (
         2,
         XMLTYPE
         ('
              <msg>
                   <data>
                        <fields>
                             <id>g2</id>
                             <dat>data2</dat>
                        </fields>
                   </data>
              </msg>
         ')
    );
    
    INSERT INTO XML_TEST
    VALUES
    (
         3,
         XMLTYPE
         ('
              <msg>
                   <data>
                        <fields>
                             <id>g3</id>
                             <dat>data3</dat>
                        </fields>
                        <fields>
                             <id>g4</id>
                             <dat>data4</dat>
                        </fields>
                        <fields>
                             <dat>data5</dat>
                        </fields>
                   </data>
              </msg>
         ')
    );
    
    SELECT
         t.id,
         x.dat,
         y.seqno,
         y.id_real
    FROM
         xml_test t,
         XMLTABLE
         (
              '/msg/data/fields'
              passing t.xml
              columns
                   dat VARCHAR2(10) path 'dat',
                   id XMLTYPE path 'id'
         )x LEFT OUTER JOIN
         XMLTABLE
         (
              'id'
              passing x.id
              columns
                   seqno FOR ORDINALITY,
                   id_real VARCHAR2(30) PATH '.'
         )y ON 1=1
    ;
    
    ID     DAT     SEQNO     ID_REAL
    --     -----     -----     -------
    1     data1     1     g1
    2     data2     1     g2
    3     data3     1     g3
    3     data4     1     g4
    3     data5          
    This is all nice, now the problem:
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bi
    PL/SQL Release 10.2.0.1.0 - Production
    "CORE     10.2.0.1.0     Production"
    TNS for HPUX: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    
    --exactly the same environment as 11g (tables and rows)
    SELECT
         t.id,
         x.dat,
         y.seqno,
         y.id_real
    FROM
         xml_test t,
         XMLTABLE
         (
              '/msg/data/fields'
              passing t.xml
              columns
                   dat VARCHAR2(10) path 'dat',
                   id XMLTYPE path 'id'
         )x LEFT OUTER JOIN
         XMLTABLE
         (
              'id'
              passing x.id
              columns
                   seqno FOR ORDINALITY,
                   id_real VARCHAR2(30) PATH '.'
         )y ON 1=1
    ;
    
    ID     DAT     SEQNO     ID_REAL
    --     -----     -----     -------
    1     data1     1     g1
    2     data2     1     g2
    3     data3     1     g3
    3     data4     1     g4
    As you can see in 10g that I don't have the last row, it seems that Oracle 10 g does not recognize the LEFT OUTER JOIN.

    Is this a bug?, Metalink says that sometimes we can have an ORA-0600, but in this case there is no error results returned, just incorrect.

    Help, please.

    Kind regards.

    What about try the original Oracle method for outer joins? Using (+) without the extra space

    XMLTABLE(...COLUMNS ... id XMLTYPE PATH ... ) x,
    XMLTABLE(... PASSING x.id ...) (+) y
    

Maybe you are looking for

  • Distribution of the source - unit test dependency problem

    Hello I developed and API and I want to make the distribution of the sources, however my faulty build (error message is below) due to the error of reclassification of the Unit Test framework that I use to test my code. All Unit Tests are in the same

  • Parental controls does not Windows 7 times

    I am using windows 7 Home and Windows Live essential 2011.  When I try to turn on the delays and app and game restrictions, the feature tells me that I have to upgrade to windows 7 and create a standard account.  The account for my children is a stan

  • VAIO Duo 13 touchscreen does not well during the charge. Stop charge in battery mode, it's ok.

    Any user of Duet 13 having problems with the touch screen when the load on the sector? Touch screen keyboard reacts not well, or does not capture the key pressed during the loading of the machine. However, once load stop and battery operated, things

  • Adding RDP to access without client

    Need information about the addition of plug-in for VPN users without RDP client.  I would like to send users to Tem-network server only.  Device is windows server 2012.

  • How to install Java?

    Hi allEBS 11iRHEL 5I want version of the JDK to upgrade the node for the server HTTP.I downloaded jdk-1_5_0_15-linux-i586 - rpm.bin and install[root@oracle]# chmod 777 jdk-1_5_0_15-linux-i586 - rpm.bin][root@roracle]#./jdk-1_5_0_15-linux-i586-rpm.bin