Bug in outer join syntax?

I use Oracle 10.2, and I think I found a bug in what is allowed for the outer join syntax. Specifically, I am allowed to specify "outer join" without specifying if it's left, right, or full outer join. It behaves as an inner join.

The documents show that the type_de_jointure is optional, but does not allow the 'outside' keyword be used alone: http://download.oracle.com/docs/cd/A97630_01/server.920/a96540/statements_103a.htm#2126207

Small example:
create table TABLE_A (ID number(10) primary key, VALUE_A varchar2(50));
create table TABLE_B (ID number(10) primary key, VALUE_B varchar2(50));
insert into TABLE_A (ID, VALUE_A) values (1, 'abc');
insert into TABLE_A (ID, VALUE_A) values (2, 'def');
insert into TABLE_A (ID, VALUE_A) values (3, 'ghi');
insert into TABLE_B (ID, VALUE_B) values (2, 'jkl');
insert into TABLE_B (ID, VALUE_B) values (3, 'mno');
insert into TABLE_B (ID, VALUE_B) values (4, 'pqr');
commit;
select ID, VALUE_A from TABLE_A;
select ID, VALUE_B from TABLE_B;
select ID, VALUE_A, VALUE_B from TABLE_A join TABLE_B using (ID);
select ID, VALUE_A, VALUE_B from TABLE_A full outer join TABLE_B using (ID);
select ID, VALUE_A, VALUE_B from TABLE_A outer join TABLE_B using (ID);
The release of the last three selects shows that the OUTER JOIN behaves as a simple JOIN, rather than return a syntax error or at least behave like a FULL OUTER JOIN (this is where the absence of a syntax error is misleading):
SQL> select ID, VALUE_A, VALUE_B from TABLE_A join TABLE_B using (ID);

        ID VALUE_A                                            VALUE_B
---------- -------------------------------------------------- --------------------------------------------------
         2 def                                                jkl
         3 ghi                                                mno

SQL> select ID, VALUE_A, VALUE_B from TABLE_A full outer join TABLE_B using (ID);

        ID VALUE_A                                            VALUE_B
---------- -------------------------------------------------- --------------------------------------------------
         1 abc
         2 def                                                jkl
         3 ghi                                                mno
         4                                                    pqr

SQL> select ID, VALUE_A, VALUE_B from TABLE_A outer join TABLE_B using (ID);

        ID VALUE_A                                            VALUE_B
---------- -------------------------------------------------- --------------------------------------------------
         2 def                                                jkl
         3 ghi                                                mno

SQL> 
Y at - there somewhere that I can tell you that?

If you have a supported Oracle agreement you can save a Service request with Oracle, but they can answer that this is not a bug. The problem is that the 'outside' keyword in your 3rd example is treated as an alias for TABLE_A because it is not considered as a reserved keyword.

with table_a as (
select 1 as id, 'abc' as value_a from dual union all
select 2 as id, 'def' as value_a from dual union all
select 3 as id, 'ghi' as value_a from dual

)
, table_b as (
select 2 as id, 'jkl' as value_b from dual union all
select 3 as id, 'mno' as value_b from dual union all
select 4 as id, 'pqr' as value_b from dual
)
select ID, outer.VALUE_A, VALUE_B from TABLE_A outer join TABLE_B using (ID);

ID                     VALUE_A VALUE_B
---------------------- ------- -------
2                      def     jkl
3                      ghi     mno

If you query the view RESERVED_WORDS of V$ it will tell you what keywords are reserved.

select * from V$RESERVED_WORDS where keyword in ('OUTER', 'SELECT','USING');

KEYWORD                        LENGTH                 RESERVED RES_TYPE RES_ATTR RES_SEMI DUPLICATE
------------------------------ ---------------------- -------- -------- -------- -------- ---------
USING                          5                      N        N        N        N        N
OUTER                          5                      N        N        N        N        N
SELECT                         6                      Y        N        N        N        N

You'll get a similar result, if you tried

select ID, VALUE_A, VALUE_B from TABLE_A using join TABLE_B using (ID);

Kind regards
Bob

Tags: Database

Similar Questions

  • Former Outer Join syntax on constants

    Hello

    Can someone please tell me why the below two queries are performing differently. How to join a constant by using the old syntax used.

    Also, how is 3 different query of query 2?

    CREATE TABLE T1 (X VARCHAR2 (10), B INTEGER);

    CREATE TABLE T2 (Y VARCHAR2 (10), B INTEGER);

    INSERT INTO T1 VALUES('XXX',10);
    INSERT INTO T1 VALUES('XXX',10);
    INSERT INTO T1 VALUES('XXX',10);
    INSERT INTO T1 VALUES('YYY',20);
    INSERT INTO T1 VALUES('YYY',20);
    INSERT INTO T1 VALUES('YYY',20);

    INSERT INTO T2 VALUES('AAA',10);
    INSERT INTO T2 VALUES('BBB',20);

    Query 1

    SELECT T1.*, T2.* FROM T1 LEFT JOIN T2

    ON T1. B = T2. B

    AND T1. B = 20

    -OUTPUT

    =========

    BBB YYY 20 20

    BBB YYY 20 20

    BBB YYY 20 20

    NULL NULL 10 XXX

    NULL NULL 10 XXX

    NULL NULL 10 XXX

    Query 2

    SELECT T1.*, T2.* FROM T1, T2

    ON T1. B (+) = T2. B

    AND T1. B ( + ) = 20;

    OUTPUT

    =======

    BBB YYY 20 20

    BBB YYY 20 20

    BBB YYY 20 20

    Request 3

    SELECT T1.*, T2.* FROM T1, T2

    ON T1. B (+) = T2. B

    ET T2. B ( + ) = 20;

    -OUTPUT

    =========

    BBB YYY 20 20

    BBB YYY 20 20

    BBB YYY 20 20

    NULL NULL 10 XXX

    NULL NULL 10 XXX

    NULL NULL 10 XXX

    Thank you and best regards,

    Mathieu

    Hi, nada.

    967250 wrote:

    Hello

    My apologies for errors in queries.

    Please find the three queries

    QUERY1

    SELECT T1.*, T2.*
    T1 LEFT JOIN T2
    ON T1. B = T2. B
    AND T1. B = 20;

    QUERY2

    SELECT T1.*, T2.*
    FROM T1, T2
    WHERE T1. B = T2. B ( + )
    AND T1. B (+) = 20;

    QUERY3
    SELECT T1.*, T2.*
    FROM T1, T2
    WHERE T1. B = T2. B ( + )
    AND T2. B (+) = 20;

    Query 1 and 3 produce the same results. I want to know is what is the difference between Q2 and (T1 or T3)

    Thank you

    Mathieu

    In the query above 1, t1 is the required table (LEFT OUTER JOIN means the table on the LEFT is needed, and the other table is optional).

    Query 3 is the way to do the same in the old notation.

    If you use the old notation of outer join, the + sign is used by reference to the table as an option.  It should always apply for t1 or t2, not sometimes one and sometimes the other, which is what you do in the application 2.  In the State:

    T1. B = T2. B ( + )

    you say that t2 is optional; in the other condition

    T1. B (+) = 20

    you say that t1 is optional.  I don't know why that does not raise an error.  Apparently, it is just to ignore the sign in this last condition.

  • LEFT OUTER JOIN SYNTAX?

    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production 64-bit
    With partitioning, OLAP, Data Mining and Real Application Testing options

    When I run:
    SELECT ACCF. SPECIMEN_ID as ACC_ID,
    ACCF. PREFIX,
    ACCF. SPECIMEN_NBR as ACC_NBR,
    RP. PHYSICIAN_ID as REFPHY_BUS_KEY,
    ACCF. SIGNOUTLOC,
    THE. Location_id as LAB_BUS_KEY,
    ACCF. COLLDATE as ACC_SPCMN_COLL_DT_ID,
    ACCF. ACDATE as ACC_CREATED_DT_ID,
    ACCF. SODATEORIG as ACC_ORIG_SIGNOUT_DT_ID,
    ACCF. SODATE as ACC_SIGNOUT_DT_ID
    OF ACC_FACT_WS ACCF.
    REFPHY_WS RP,
    THE LAB_WS
    WHERE ACCF. BLINK = RP. PHYSICIAN_ID
    AND ACCF. ACDATE > to_date('2010-06-17','YYYY-MM-DD')
    AND ACCF. PREFIX = A '
    AND ACCF. SIGNOUTLOC = (LOUISIANA). LOCATION_ID

    It works fine, but I really have an outer join on LAB_WS.
    When I run with an outer join, I get:
    SQL > SELECT ACCF. SPECIMEN_ID as ACC_ID,
    2 ACCF. PREFIX,
    3 ACCF. SPECIMEN_NBR as ACC_NBR,
    4. PR PHYSICIAN_ID as REFPHY_BUS_KEY,
    5 ACCF. SIGNOUTLOC,
    6. THE. Location_id as LAB_BUS_KEY,
    ACCF 7. COLLDATE as ACC_SPCMN_COLL_DT_ID,
    ACCF 8. ACDATE as ACC_CREATED_DT_ID,
    ACCF 9. SODATEORIG as ACC_ORIG_SIGNOUT_DT_ID,
    ACCF 10. SODATE as ACC_SIGNOUT_DT_ID
    11 ACC_FACT_WS ACCF,
    12 REFPHY_WS RP
    13 LEFT OUTER JOIN LAB_WS ON ACCF. SIGNOUTLOC = (LOUISIANA). LOCATION_ID
    14. WHERE ACCF. BLINK = RP. PHYSICIAN_ID
    15 AND ACCF. ACDATE > to_date('2010-06-17','YYYY-MM-DD')
    16 AND ACCF. PREFIX = A ';
    LEFT OUTER JOIN LAB_WS ON ACCF. SIGNOUTLOC = (LOUISIANA). LOCATION_ID
    *
    ERROR on line 13:
    ORA-00904: "ACCF. "" SIGNOUTLOC ": invalid identifier

    The previous query shows ACCF. SIGNOUTLOC is not the problem.
    What is the problem and how to fix it?
    Note: the syntax of the old outer join is not an option. The query will be finally 9 outer joins.

    Thank you
    Jon Jacobs

    Hello

    You are mixing syntax to join Oracle with ANSI, which is sometimes delicate.
    Best is to use a unique syntax, for example ANSI:

    ...
    FROM ACC_FACT_WS ACCF
         JOIN REFPHY_WS RP ON ACCF.CLIN = RP.PHYSICIAN_ID
         LEFT OUTER JOIN LAB_WS LA on ACCF.SIGNOUTLOC = LA.LOCATION_ID
    WHERE ACCF.ACDATE > to_date('2010-06-17','YYYY-MM-DD')
    AND ACCF.PREFIX = 'D'
    
  • Need help with outer join

    Hello

    I have a requirement in which I need to get data from a third table where a date of the third table is higher than a date in the second array.

    Ex:

    SELECT t1.column1, t3.column2
    FROM t1, t2, t3
    WHERE t1.id = t2.foreign_id
    AND t1.id ( + ) = t3.foreign_id
    AND t3.some_date_column > t2.another_date_column
    
    

    However, using the query above returns no results if the date condition is not met. I still need to show t1.column1 and a null t3.column2.

    How should I do this?

    Thank you

    Allen

    Edit: Added information about the requirement.

    Hi Allen

    1. SELECT t1.column1, t3.column2
    2. T1, t2, t3
    3. WHERE t1.id = t2.foreign_id
    4. AND t1.id = t3.foreign_id (+)
    5. AND t3.some_date_column (+) > t2.another_date_column

    I guess that this t1.column1 must not be null. Or am I wrong? The + sign must be placed on the side where draws are accepted. You must repeat it for each condition on the table.

    Alternativlely you can use the LEFT OUT JOIN syntax. If the two columns are allowed null you need a FULL OUTER JOIN.

    BTW: The join to t2 is not required if a refefernce constraint forced.

  • Outer joins in terms?

    Hello

    I have the following code in one of my procedures, which I have never seen so far.

    Where IsActive (+) = 'Y '.

    Can someone tell me what is the purpose of the (+) singing in the condtion? Thanks in advance.

    Here's a simple example.  The first query is an outer join and work as expected.  But if we remove the outer join of the second example (on line 7), the query goes back to be an inner join.  Regardless of the other outer join syntax, this line says b.col2 * must * be equal to 1.

    SQL > with one also (select 1 col1, col2 1 Union double all the)
    2 Select 2 col1, col2 2 double)
    3, b as (1 select col1, col2 1 of double)
    4 Select
    5A, b
    6 where a.col1 = b.col1 (+)
    7 and b.col2 (+) = 1
    8;

    COL1 COL1 COL2 COL2
    -------------------- -------------------- -------------------- --------------------
    1                    1                    1                    1
    2                    2

    SQL > with one also (select 1 col1, col2 1 Union double all the)
    2 Select 2 col1, col2 2 double)
    3, b as (1 select col1, col2 1 of double)
    4 Select
    5A, b
    6 where a.col1 = b.col1 (+)
    7 and b.col2 = 1
    8;

    COL1 COL1 COL2 COL2
    -------------------- -------------------- -------------------- --------------------
    1                    1                    1                    1

  • My Confusion of outer join

    Oracle 10g

    I have three below queries that use the outer join syntax.

    All three queries return exactly the same results


    (a)
    SELECT TA.ID TA
         , TB.ID TB
      FROM TA
         , TB
     WHERE TA.ID = TB.ID(+);
    (b)
    SELECT TA.ID TA
         , TB.ID TB
      FROM TA
         , TB
     WHERE TB.ID(+) = TA.ID;
    (c)
    SELECT TA.ID TA
         , TB.ID TB
      FROM TA
      LEFT OUTER JOIN TB ON TA.ID = TB.ID;
    I have the right call outer join query because the (+) sign is located on the right and outer join query (b) left because the (+) sign is on the left?

    Or is the left join or right determined by the join columns specified in the order select it?



    Create the Script
    CREATE TABLE TA
      (
        "ID" NUMBER
      );
    
    CREATE TABLE TB
      (
        "ID" NUMBER
      );
    
    INSERT INTO TA (ID) VALUES ('1');
    INSERT INTO TA (ID) VALUES ('2');
    INSERT INTO TA (ID) VALUES ('3');
    
    INSERT INTO TB (ID) VALUES ('1');
    INSERT INTO TB (ID) VALUES ('2');
    INSERT INTO TB (ID) VALUES ('4');
    Ben

    Published by: benton on August 15, 2012 08:16

    Hi, Ben.

    Benton says:
    ... So is it correct to say that the left or right refers to which side the null values will be displayed?

    Lol it is incorrect to say that the old syntax outer join (using the sign +) is either a left - or a right outer join.

    ... So I need to have the order of the columns in the correct SELECTION so that there is no likelihood of confusion over which side will display NULL values. If I place the columns A and B in the wrong order, that is to say B then a I'll lend to confusion about what will be returned with respect whether left or right.

    No, do not hesitate to organize columns in the select in any way will help your users the most. What is happening in the FROM and WHERE clause, in particular the order in which the tables happens to appear, may not have something to do with the order of the columns in the output.
    Many readers are more comfotable with having NULL columns at the end of a line of output, or at least not at the beginning, so maybe it's one of the reasons for ta.id first in your example. Rearrange the columns in the game any way more than makes sense for people who will look at them.

  • outer join information

    Dear expert;

    If you look at the section of outer join. The user asserts that there is no complete equivalent in the outer join syntax. Is it true.

    http://www.Oracle-base.com/articles/9i/ANSIISOSQLSupport.php

    If this is not the case, no one knows the equivalent. Thank you

    It's true, but you can do something similar by using the UNION.

    Example of
    http://www.Oreillynet.com/network/2002/04/23/fulljoin.html

    Concerning
    Peter

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

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

  • outer join with syntax plus sign

    To do this in Sql outer joins can be used as grammar:
    ( + )
    What are the standards (ISO, ANSI and what version) created this grammar?
    Or is it only the invention of Oracle?

    Published by: CharlesRoos on July 1st, 2010 07:23

    Apparently, he was "there are chandeliers" ;)

    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:2419891400346921578 #2439016200346544570

  • Diff "full outer join" is going. "(+)" SELECT syntax?

    As far as I know there are two ways to set an outer join:

    Select... from tab1 external t1 full join tab2 t2 on t1.id = t2.id;
    or:
    SELECT... from tab1 tab2 t2, t1 where t1.id = t2.id (+)

    They are absolutely equivialent?

    Who are the most common one?

    Who serve as well on other databases (DB2, MySQL)?

    Can I put an additional WHERE clause at the end of the first statement:

    SELECT... from tab1 t1 outer join t2 on t1.id = t2.id tab2 complete WHOSE...;

    Select... from tab1 external t1 full join tab2 t2 on t1.id = t2.id;

    It's FULL OUTER JOIN

    SELECT... from tab1 tab2 t2, t1 where t1.id = t2.id (+)

    It's LEFT OUTER JOIN.

    They are quite different.

    FULL OUTER JOIN - retrieves all the rows from tab1 and tab2

    LEFT OUTER JOIN - gets all the tab1 and lines than the line that matches the join condition of tab2.

    Here is a simple test.

    create table tab1(id integer)
    /
    create table tab2(id integer)
    /
    begin
      insert into tab1 values(1);
      insert into tab1 values(2);
      insert into tab1 values(3);
    end;
    /
    begin
      insert into tab2 values(3);
      insert into tab2 values(4);
      insert into tab2 values(5);
    end;
    /
    Select t1.id, t2.id
      from tab1 t1 full outer join tab2 t2
        on t1.id =t2.id
    /
    Select t1.id, t2.id
      from tab1 t1, tab2 t2
     where t1.id = t2.id(+)
    /
    

    Run it and see the result.

  • use the ansi join syntax

    From what I've been reading is preferable to use the new syntax (don't know how is it news)

    The ANSI join syntax was new to Oracle in Oracle 8i in 1998 - that is 15 years old.

    It can produce more readable code and is also much more readable and less human-source of errors for outer joins.

    The ANSI format allows an outer join between several tables in a way the old (+) syntax specific to oracle does not and introduced the JOIN FULL OUTER you should use very rarely.

    You should not use NATURAL JOIN in code - add columns not related to the tables involved can give very different results.

    There have not been important bugs for ANSI joins in Oracle from Oracle 10.2 set up about 8 years ago.

    As Paul says, the part on should be the criteria to join between the tables. Did clause should be the filtering of the joined tables.

    So assuming start_date and end_date in_property_id are variable

    SELECT resv_num, unit_date

    OF p_resv_unit ru

    INNER JOIN p_pm_unit_night pun

    ON pun.resv_unit_id = ru.resv_unit_id

    WHERE pun.property_id = in_property_id

    AND pun.unit_date BETWEEN start_date AND end_date

    AND pun.pm_unit_num = cvUnitNum;

    If start_date and end_date are the columns of p_resv_unit the query would be:

    SELECT resv_num, unit_date

    OF p_resv_unit ru

    INNER JOIN p_pm_unit_night pun

    ON pun.resv_unit_id = ru.resv_unit_id AND pun.unit_date BETWEEN ru.start_date AND ru.end_date

    WHERE pun.property_id = in_property_id

    AND pun.pm_unit_num = cvUnitNum;

    Inner join queries work with criteria in the wrong place, but they are harder to read. Outer joins do not work unless you put the criteria in the right place.

  • SSRS for lack of outer join with the Oracle data source

    It seems to be a problem with the Oracle driver used in the Reporting SERVICES query designer.

    When you use an Oracle data source, if I create an outer join in the graphic designer, it automatically inserts '{OJ' before the join and '} ' after her.  This is an incorrect syntax for Oracle and refuses to start.  The curly braces and the JO editable in designer text, but if I go back to the graphic designer and immediately to reintegrate them.

    Only, this has started to happen a year or two ago - before that it worked, but with the old (+) syntax.

    Can it not be healed?  It makes things very difficult.

    -Geoff

    Hi Geoff,

    Thanks for posting in the Microsoft Community.

    However, the question you posted would be better suited in the Forums of the Oracle Support; We recommend that you post your query in Oracle Support Forums to get help:

    https://forums.Oracle.com/forums/main.jspa;JSESSIONID=8d92100c30d8fb401bcbd10b46c38c9ddf1a3242549a.e34SbxmSbNyKai0Lc3mPbhmSc3aNe0? CategoryID = 84

    If you have any other questions or you need Windows guru, do not hesitate to post your questions and we will be happy to help you.

  • Outer join does not not as expected left

    Hi all

    I have it here are three tables with values. Mentioned the under outer join query does not and behave like the inner query.

    CREATE TABLE RET_FUND_FEE

    (

    NPTF VARCHAR2 (8 CHAR),

    TPART VARCHAR2 (4 CHAR)

    );

    CREATE TABLE PART_PTF

    (

    Mf_Id VARCHAR2 (6 CHAR) NOT NULL,

    TPARTS VARCHAR2 (4 CHAR) NOT NULL

    );

    CREATE TABLE TFC_FUNDS

    (

    NPTF VARCHAR2 (8 CHAR) NOT NULL,

    MULTIFONDS_ID VARCHAR2 (6 CHAR)

    );

    INSERT INTO RET_FUND_FEE VALUES('111','A');

    INSERT INTO RET_FUND_FEE VALUES('111','D');

    INSERT INTO RET_FUND_FEE VALUES('111','E');

    INSERT INTO PART_PTF VALUES ('MF1', 'A');

    INSERT INTO PART_PTF VALUES ('MF1', 'B');

    INSERT INTO PART_PTF VALUES('MF1','C');

    INSERT INTO TFC_FUNDS VALUES('111','MF1');

    INSERT INTO TFC_FUNDS VALUES('111','MF1');

    INSERT INTO TFC_FUNDS VALUES('111','MF1');

    SELECT A.TPART, B.TPARTS, A.NPTF, B.Mf_Id, C.MULTIFONDS_ID, C.NPTF

    OF RET_FUND_FEE A, PART_PTF B, TFC_FUNDS C

    WHERE A.NPTF = C.NPTF

    AND C.MULTIFONDS_ID = B.Mf_Id

    AND A.TPART = B.TPARTS (+)

    AND C.MULTIFONDS_ID = 'MF1 '.

    AND C.NPTF = '111'

    Here, I expect all records in the RET_FUND_FEE table that I am using outer join.

    But I'm only corresponding chronogram RET_FUND_FEE, PART_PTF as an inner join. Can you get it someone please let me know what lack us.

    Is my version of oracle 11g

    SELECT

    A.TPART, B.TPARTS, A.NPTF, B.Mf_Id, C.MULTIFONDS_ID, C.NPTF

    Of

    PART_PTF B

    Join

    C TFC_FUNDS

    on (C.MULTIFONDS_ID = B.Mf_Id

    AND C.MULTIFONDS_ID = 'MF1 '.

    AND C.NPTF = '111'

    )

    right outer join

    RET_FUND_FEE HAS

    on (A.TPART = B.TPARTS

    and A.NPTF = C.NPTF) - added as correction

    TPART TPARTS NPTF MF_ID MULTIFONDS_ID NPTF
    A A 111 MF1 MF1 111
    A A 111 MF1 MF1 111
    A A 111 MF1 MF1 111
    E - 111 - - -
    D - 111 - - -

    or

    SELECT A.TPART, d.TPARTS, A.NPTF, d.Mf_Id, d.MULTIFONDS_ID, d.NPTF

    OF RET_FUND_FEE HAS

    , (

    Select

    *

    PART_PTF b, TFC_FUNDS C

    where B.Mf_Id = C.MULTIFONDS_ID

    AND C.MULTIFONDS_ID = 'MF1 '.

    AND C.NPTF = '111'

    ) d

    WHERE A.TPART = D.TPARTS (+)

    and A.NPTF = D.NPTF (+) - added as a correction

    Sorry had to correct the syntax oracle solution.

    The first one was bad because it would return also B lines that have no match in C.

    Sorry a correction more on these two approaches, missed the second predicate.

  • Bad result in a left outer join in 12.1.0.2

    Hallo,

    We discovered a strange behaviour in a query. The query provides values in a column of outer join where there is no corresponding value in the table is attached to the outside.

    When you expand this request by the "ORDER BY" then this query gives the correct result.

    Example:

    SQL > desc tb_a
    Name                                Null?    Typ
    -------------------------------------------- ----------------------------
    ID NOT NULL NUMBER (19)

    SQL > desc tb_b
    Name                                Null?    Typ
    -------------------------------------------- ----------------------------
    CLOSED NOT NULL NUMBER (1)
    ID NOT NULL NUMBER (19)

    CCS_APPLICATION@icw01> select * from tb_a where id in (4148,4141,4195);

    ID
    ----------
    4148
    4141
    4195

    CCS_APPLICATION@icw01> select * from tb_b where id in (4148,4141,4195);

    INTERNAL ID
    ---------- ----------
    4148 0

    CCS_APPLICATION@icw01> SELECT
    2      b.id                            AS b_id,
    3      a.id                            AS a_id,
    4 b.closed AS b_closed
    5
    6 tb_a a
    7 LEFT OUTER JOIN tb_b b ON a.id = b.id
    8 WHERE a.id IN (4148, 4195, 4141)
    9 ORDER BY ASC a.id
    10;

    B_ID ALLOCATION A_ID B_CLOSED
    ---------- ---------- ----------
    4141
    4148 4148 0
    4195

    CCS_APPLICATION@icw01> SELECT
    2      b.id                            AS b_id,
    3      a.id                            AS a_id,
    4 b.closed AS b_closed
    5
    6 tb_a a
    7 LEFT OUTER JOIN tb_b b ON a.id = b.id
    8 WHERE a.id IN (4148, 4195, 4141)
    9 - ORDER BY ASC a.id
    10;

    B_ID ALLOCATION A_ID B_CLOSED
    ---------- ---------- ----------
    4148 4148 0
    4141 4141
    4195 4195

    instance parameter:

    VALUE OF TYPE NAME

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

    compatible string 12.1.0.2.0

    optimizer_features_enable string 12.1.0.2

    After ""alter system set optimizer_features_enable = ' 11.2.0.4 ';"  the query provides the correct result in both cases (ordered and unordered).

    Now the final question: is this a bug?

    1480970 wrote:

    Hallo!  Yes, I searched the Support of Oracle. I found some similar entries, but not an exact match. To fix some issues

    with 12.1.0.2.

    There is another interesting clue when look you on the execution plan:

    Note

    -----

    -the dynamic statistics used: dynamic sampling (level = 2)

    - This is an adaptation plan

    We have disabled (= FALSE) optimizer_adaptive_features and the query provides the correct values.

    This could be a solution for us.

    Looks like a pretty tight match for bug 18430870, even if it affects the two 12.1.0.1 and 12.1.0.2, which contradicts the Martin trial against 12.1.0.1.

    The description of the bug mentions disabling "_projection_pushdown" (set to false) should also be a viable solution, perhaps if you want to give that a try and see if it is a different bug or not.

    There are also a number of one-time fixes already available for download, maybe your version / platform is already covered, if the bug applies.

    Randolf

Maybe you are looking for