BAD RESULTS WITH OUTER JOINS AND TABLES WITH A CHECK CONSTRAINT

HII All,
Could any such a me when we encounter this bug? Please help me with a simple example so that I can search for them in my PB.


Bug:-8447623

Bug / / Desc: BAD RESULTS WITH OUTER JOINS AND TABLES WITH a CHECK CONSTRAINT


I ran the outer joins with check queries constraint 11G 11.1.0.7.0 and 10 g 2, but the result is the same. Need to know the scenario where I will face this bug of your experts and people who have already experienced this bug.


Version: -.
SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
CORE    11.1.0.7.0      Production
TNS for Solaris: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - Production

Why do you not use the description of the bug test case in Metalink (we obviously can't post it here because it would violate the copyright of Metalink)? Your test case is not a candidate for the elimination of the join, so he did not have the bug.

Have you really read the description of the bug in Metalink rather than just looking at the title of the bug? The bug itself is quite clear that a query plan that involves the elimination of the join is a necessary condition. The title of bug nothing will never tell the whole story.

If you try to work through a few tens of thousands of bugs in 11.1.0.7, of which many are not published, trying to determine whether your application would be affected by the bug? Wouldn't be order of magnitude easier to upgrade the application to 11.1.0.7 in a test environment and test the application to see what, if anything, breaks? Understand that the vast majority of the problems that people experience during an upgrade are not the result of bugs - they are the result of changes in behaviour documented as changes in query plans. And among those who encounter bugs, a relatively large fraction of the new variety. Even if you have completed the Herculean task of verifying each bug on your code base, which would not significantly easier upgrade. In addition, at the time wherever you actually performed this analysis, Oracle reportedly released 3 or 4 new versions.

And at this stage would be unwise to consider an upgrade to 11.2?

Justin

Tags: Database

Similar Questions

  • Problem with Outer join and filter

    Hello

    I join two tables in the source using a left outer join. Outside of the join, I have a filter specified with condition TabA.C1 > TabB.C2.

    Now, when ODI generates the query it puts the left outer join on the filter condition as well. So he puts filter as

    where
    (1 = 1)
    And ((TabA.C1 = TabB.C1 (+)) AND)
    (TabA.C2 = TabB.C2 (+))
    And TabA.C10 > TabB.C14 (+)

    How to avoid this problem. I tried this performance on stage as well, always generated query remains the same.

    I use the incremental update of the IKM Oracle. My source and target are both on the same PB.


    ~ Chikk

    Hi Chikk,

    If you analyze the data, you'll see it's OK to have the "(+)" to the filter...

    Anyway, if you want to drop it, leave it as inner join and put the "(+)" manually to the join object.

    This help you?

  • Outer Join and joining several Tables

    Hello

    Oracle Database 10 g Express Edition Release 10.2.0.1.0 - product

    I have three tables AddProject, AssociateProjectLead, AddAssociate. Now I'm generating a report who will join AddProject and AssociateProjectLead for a list of all the projects, even if it doenst have a project coordinator. I used the outer join for this. However, if I want the name of the project leader, I need to search for AddAssociate table. By joining this table also, the outer join is no longer valid. Please see the result below

    CREATE TABLE  "ADDPROJECT" 
       (     "VERSIONNO" NUMBER(*,0), 
         "PROJID" VARCHAR2(20), 
         "PROJNAME" VARCHAR2(60), 
         "PROJSTARTDATE" DATE, 
         "PROJSTATUS" VARCHAR2(20), 
         "PROJENDDATE" DATE, 
         "PROJENDTYPE" VARCHAR2(20), 
         "PROJENDREASON" VARCHAR2(1000), 
         "UCPROJECTMANAGER" VARCHAR2(20), 
         "FROMDATE" DATE, 
         "TODATE" DATE, 
         "SRCHFIELD" VARCHAR2(20), 
         "OPERATOR" VARCHAR2(20), 
         "PARENTPROJID" VARCHAR2(20), 
         "PROJHIDDENDATE" VARCHAR2(20), 
          CONSTRAINT "PK_B36" PRIMARY KEY ("PROJID", "PROJHIDDENDATE") ENABLE
       )
    
    
    CREATE TABLE  "ADDASSOCIATE" 
       (     "VERSIONNO" NUMBER(*,0), 
         "ASSOCIATEID" NUMBER(9,0) NOT NULL ENABLE, 
         "ASSOCIATENAME" VARCHAR2(100) NOT NULL ENABLE, 
         "CTOJOINDATE" DATE, 
         "STATUS" VARCHAR2(20), 
         "ENDDATE" DATE, 
         "SRCHFIELD" VARCHAR2(20), 
         "OPERATOR" VARCHAR2(20), 
         "FROMDATE" DATE, 
         "TODATE" DATE, 
          CONSTRAINT "PK_B23" PRIMARY KEY ("ASSOCIATEID") ENABLE
       )
    
    CREATE TABLE  "ASSOCIATEPROJECTLEAD" 
       (     "VERSIONNO" NUMBER(*,0), 
         "PROJLEADASSOID" NUMBER(9,0), 
         "PROJID" VARCHAR2(20), 
         "ASSOCIATEID" NUMBER(9,0), 
         "PROJLEADSTARTDATE" DATE, 
         "STATUS" VARCHAR2(20), 
         "ASSOCPROJHIDDENDATE" VARCHAR2(20), 
         "PROJHIDDENDATE" VARCHAR2(20), 
         "ENDDATE" DATE, 
          CONSTRAINT "PK_B40" PRIMARY KEY ("ASSOCIATEID", "PROJID", "ASSOCPROJHIDDENDATE") ENABLE
       )
    
    
    elect ap.projid,apl.associateid
    from addproject ap, associateprojectlead apl
    where ap.projid = apl.projid(+)
    and ap.projhiddendate = apl.projhiddendate(+)
    
    
    PROJID ASSOCIATEID 
    Proj08 75825 
    Proj09 75825 
    Proj10 75825 
    Proj11 75825 
    Proj12 259811 
    Proj01 103035 
    Proj02 103035 
    Proj03 320092 
    Proj04 320092 
    Proj05 120974 
    Proj06 367393 
    Proj07 117618 
    Proj07 224882 
    Proj07 246652 
    prj001 -  
    prj001 -  
    
    16 rows returned in 0.00 seconds
    
    
    select ap.projid,apl.associateid,aa.associatename
    from addproject ap, associateprojectlead apl,addassociate aa
    where ap.projid = apl.projid(+)
    and ap.projhiddendate = apl.projhiddendate(+)
    and apl.associateid = aa.associateid
    
    
    PROJID ASSOCIATEID ASSOCIATENAME 
    Proj11 75825 Amarendra Kumar Singh 
    Proj10 75825 Amarendra Kumar Singh 
    Proj09 75825 Amarendra Kumar Singh 
    Proj08 75825 Amarendra Kumar Singh 
    Proj02 103035 Rajesh Jayaprakash 
    Proj01 103035 Rajesh Jayaprakash 
    Proj07 117618 Chetan Malhotra 
    Proj05 120974 Perumal Rajaram 
    Proj07 224882 Dilshad Ahmad 
    Proj07 246652 Shankar Kausley 
    Proj12 259811 Arunchandar Arun Vasan 
    Proj04 320092 Venkatesh Sarangan 
    Proj03 320092 Venkatesh Sarangan 
    Proj06 367393 Venkata Ramakrishna P 
    
    14 rows returned in 0.00 seconds
    How can I select all the values in table AddProject?

    Published by: Pramukh on August 23, 2012 12:18

    Hello

    I could get the result with a bit of modification

    select ap.projid,
           apl.associateid,
           aa.associatename
      from addproject ap
           left outer join
           associateprojectlead apl
        on ap.projid = apl.projid
       and ap.projhiddendate = apl.projhiddendate
           left outer join
           addassociate aa
        on apl.associateid = aa.associateid
    

    As a follow-up, I have a request more. In the report form, the user can select a particular project ID and the report should be generated as a result. For example;-he wants to see the results of the only "Proj08". I get the output as below, while the result should display only the details of 'Proj08 '.

    select ap.projid,
           apl.associateid,
           aa.associatename
      from addproject ap
           left outer join
           associateprojectlead apl
        on ap.projid = apl.projid
       and ap.projhiddendate = apl.projhiddendate
       and ap.projID = 'Proj08'
           left outer join
           addassociate aa
        on apl.associateid = aa.associateid
    ORDER BY ap.projID
    
    PROJID ASSOCIATEID ASSOCIATENAME
    Proj01 -  -
    Proj02 -  -
    Proj03 -  -
    Proj04 -  -
    Proj05 -  -
    Proj06 -  -
    Proj07 -  -
    Proj08 75825 Amarendra Kumar Singh
    Proj09 -  -
    Proj10 -  -
    Proj11 -  -
    Proj12 -  -
    prj001 -  -
    prj001 -  -  
    
  • left outer join and the where clause for the table to the right

    I want to join two tables a and b, where a is a must and b is a result set in option. When I use a left outer join to a to b, I want to achieve:

    1. Select a single column, two columns of b (not the join columns)
    2 - even if theres no friendly on the join column does not return data from one.
    3. If there is a match applies when the criteria on column b (table in option)

    so, how can I avoid no_data_found in this case? When I apply where criteria for b, so it does not return the data from one, which is a must.

    Sounds like a regular outer join to me...

    select a.col1, b.col2, b.col2
    from   tableA a
           left outer join tableB b
           on (a.id = b.id and b.colX = 'X')
    
  • Outer join, 3 tables

    Please see the attached link for table structures and data of the sample.

    There will be several lines in the table of SALES with different SALETYPEs. There may be several lines in the table RETURNS, corresponding to some of the points of SALE. RETURNS the table has a foreign key to the SALE. The report that I am trying to generate with a select sql statement must include a line for each type of sale (from table SALETYPE) and the sum of sale amounts corresponding to this type of sale of the SALES table. The table may not return the entries for all types of sales and the amount of Scripture must be reported as zero. The SQL I use is below, but does not work. I hope that I have explained this correctly. Please see the doc attached for typical data that I work with. Can someone please?

    https://spreadsheets.Google.com/pub?key=0AnDmnUJXOChwdGF2ZjdjdHFtMGF1MkJ3MWtjQ2JfUmc & hl = in & Single = true & gid = 0 & output = html

    Select SUM (s.amount) as sum_amount, t.sale_type from SALES s, SALETYPE t, r RETURNS
    where s.id = r.id
    and s.sale_type_id = t.id
    T.sale_type group;

    Published by: 801941 on October 12, 2010 15:02

    Hello - the second displays almost had. what you want to do is joining several tables at once - impossible with the syntax of the oracle, but possible if you use ANSI SQL.

    Wrote file afiedt.buf
    
      1  WITH s AS
      2   (SELECT 1 id, 1 sale_type_id, 10 amount   FROM dual
      3    UNION ALL
      4    SELECT 2, 1, 10  FROM dual
      5    UNION ALL
      6    SELECT 3, 2, 10   FROM dual
      7    UNION ALL
      8    SELECT 4, 2, 10   FROM dual
      9    UNION ALL
     10    SELECT 5, 3, 10    FROM dual
     11    UNION ALL
     12    SELECT 6, 4, 10 FROM dual),
     13  r AS
     14   (SELECT 2 sale_id   FROM dual
     15    UNION ALL
     16    SELECT 3 FROM dual
     17    UNION ALL
     18    SELECT 4 FROM dual),
     19  t AS
     20   (SELECT 1 sale_type_id, 100 sale_type    FROM dual
     21    UNION ALL
     22    SELECT 2, 200    FROM dual
     23    UNION ALL
     24    SELECT 3, 300    FROM dual
     25    UNION ALL
     26    SELECT 4, 400 FROM dual)
     27  SELECT nvl(SUM(s.amount),0) total_amount, t.sale_type
     28    FROM t
     29     join r on (1=1)
     30     left outer join s on (s.id = r.sale_id and s.sale_type_id = t.sale_type_id)
     31   --WHERE s.id(+) = r.sale_id
     32  --   AND s.sale_type_id(+) = t.sale_type_id
     33   GROUP BY t.sale_type
     34*  order by t.sale_type
    SQL> /
    
    TOTAL_AMOUNT  SALE_TYPE
    ------------ ----------
              10        100
              20        200
               0        300
               0        400
    
    4 rows selected.
    

    The two commented lines are what you are trying to achieve using the syntax of the oracle, but which will give you an error.

  • outer join and LignesMax problem left

    I'm having a problem with the method and an sql join. My left table includes some documents that I want in the list, max 25 per page. These records have some notes are related in another table that is outer joined. When I specify the method in my cfoutput tag it includes my external joined table rows. So I could only go 5 records in my table left and 20 of my attachment table. What I want is 25 records in my table on the left and however the number of records in the table on the other that could be associated with these 25 records. Is this possible?

    I make two requests and avoid the outer join in this case:

  • Outer joins and null in the 'where' clause condition

    Hi people,

    Please help me on this.

    Here's my query.

    with x

    (select 'a' as a dual union all col1)

    Select 'b' as col1 of union double all the

    Select 'c' as double col1

    ),

    y as

    (

    Select 'b' as col2 from dual Union all the

    Select 'c' as col2 from dual Union all the

    Select would be "as col2 from dual Union all the"

    Select 'e' as col2 from dual

    )

    Select * x y right outer join

    on x.col1 = y.col2 and y.col2 is null

    Get all the lines of 'COL1' as null. Why like this?

    Just add the condition to the WHERE clause for example

    WITH x AS
    (SELECT 'a' AS col1 FROM dual UNION ALL
    SELECT 'b' AS col1 FROM dual UNION ALL
    SELECT 'c' AS col1 FROM dual
    ),
    y AS
    (
    SELECT 'b' AS col2 FROM dual UNION ALL
    SELECT 'c' AS col2 FROM dual UNION ALL
    SELECT 'd' AS col2 FROM dual UNION ALL
    SELECT 'e' AS col2 FROM dual
    )
    SELECT * FROM x LEFT OUTER JOIN y
    ON x.col1=y.col2                     ----want to add "and y.col2 is null " condition to get value "a"
    where y.col2 is null
    
  • Outer join on tables

    Hello I am trying to improve my self, I am working on the user for example HR oracle tablespaces

    HR diagram
    http://img.Photobucket.com/albums/v346/satanix/hrschema.PNG

    Select * from
    employees a
    job_history.employee_id = a.employee_id left outer join job_history
    departments of outer join left on departments.department_id = a.department_id
    outer join left on jobs.job_id jobs = a.job_id

    There is no problem up to now, but when I add

    locations of outer join left on locations.location_id = departments.department_id
    country of outer join left on countries.country_id = locations.country_id
    regions of outer join left on regions.region_id = countries.region_id

    they came to the table with null values

    Please help thanks

    Select * from
    employees a
    job_history.employee_id = a.employee_id left outer join job_history
    departments of outer join left on departments.department_id = a.department_id
    outer join left on jobs.job_id jobs = a.job_id
    locations of outer join left on locations.location_id = departments.location_id
    country of outer join left on countries.country_id = locations.country_id
    regions of outer join left on regions.region_id = countries.region_id

    Probably the above query might work
    Please check the answer correct or useful, if it is

  • outer join and OR condition

    Hello world

    I have a query that is not working properly. I'm trying to join two tables and I or condition and outer join
    I get the error message
     ORA-01719: outer join operator (+) not allowed in operand of OR or IN
    
    my query is as follow
    
    SELECT l.* FROM table1 l, table2 map
    WHERE (NVL(l.id, '-99') = NVL(map.id(+), NVL(l.id, '-99'))
            AND  l.TYPE = 'TKE')
          ) OR 
        (NVL(l.id, '-99') = NVL(map.id(+), NVL(l.id, '-99'))
    AND NVL(l.type, '-99') = NVL(map.type(+), NVL(l.type, '-99'))
    AND NVL(l.pos_22, '-99') = NVL(map.pos_22(+),NVL(l.pos_22, '-99'))
    AND NVL(l.pos_27, '-99') = NVL(map.pos_27(+),NVL(l.pos_27, '-99'))
    AND NVL(l.pos_17, '-99') = NVL(map.pos_17(+),NVL(l.pos_17, '-99'))
    AND NVL(l.pos_18, '-99') = NVL(map.pos_18(+),NVL(l.pos_18, '-99'))
    AND NVL(l.pos_12, '-99') = NVL(map.pos_12(+),NVL(l.pos_12, '-99'))
    AND NVL(l.pos_16, '-99') = NVL(map.pos_16(+),NVL(l.pos_16, '-99'))
    AND NVL(l.pos_34, '-99') = NVL(map.pos_34(+),NVL(l.pos_34, '-99'))
    AND NVL(l.pos_43, '-99') = NVL(map.pos_43(+),NVL(l.pos_43, '-99'))
    AND NVL(l.pos_14, '-99') = NVL(map.pos_14(+),NVL(l.pos_14, '-99'))
    AND NVL(l.status_cd, '-99') = NVL(map.status(+),NVL(l.status_cd, '-99'))
    AND NVL(l.action_cd,'-99') = NVL(map.action_cd(+), NVL(l.action_cd,'-99'))
    AND NVL(l.sys,'-99') = NVL(map.sys(+), NVL(l.sys,'-99'))
    AND NVL(l.ind,'-99') = NVL(map.ind(+), NVL(l.ind,'-99'))
      )
    So, basically in the above query I say that if the type = "TKE" do not join on all columns of pos. If type is not TKE then do all the joints on all columns POS etc.
    How do I rewrite query so that I can use OR and the outer JOIN in the same query?

    Hello

    It is one of several good reasons to use the ANSI join syntax. Move all the join conditions in the clause on, not the WHERE clause, and you do not use the sign +.

    SELECT  l.*
    FROM           table1 l
    LEFT OUTER JOIN  table2 map  ON   (    NVL(l.id, '-99') = COALESCE (map.id, l.id, '-99')
                                        AND  l.TYPE = 'TKE'
                          )
                                 OR  (     NVL (l.id, '-99') = COALESCE (map.id, l.id, '-99')
                              AND   NVL (l.type, '-99') = COALESCE (map.type), l.type, '-99')
                         ...
    

    Instead of nesting the NVL statements, use COALESCE, as illustrated above. It is independent of the issue of the join.

  • You will need to validate the format of the time 24 hours with the check constraint.

    Hello

    I need to validate a field in a table with 24 h format. I created forced bellows, but not validating the only of numbers. Pls help me on this.

    ALTER TABLE ADD RESERVATION

    CONSTRAINT CNST_CHK_VB_ACT

    CHECK (regexp_like (law on the ' [[: digit:]] {4}'))

    ENABLE

    NOVALIDATE;

    Rgds,

    Athuru Mithuru.

    Hi, Athuru,

    Athurumithuru wrote:

    Hello

    I need to validate a field in a table with 24 h format. I created forced bellows, but not validating the only of numbers. Pls help me on this.

    ALTER TABLE ADD RESERVATION

    CONSTRAINT CNST_CHK_VB_ACT

    CHECK (regexp_like (law on the ' [[: digit:]] {4}'))

    ENABLE

    NOVALIDATE;

    Rgds,

    Athuru Mithuru.

    Let's start by defining precisely what you want.  For example

    1. The 1st character can be 0, 1, or 2.
    2. The 2nd character can be any number EXCEPT if the 1st character is '2', then the 2nd character must be in the range ' 0 'to 3'.
    3. The 3rd character can be '0' and '5'
    4. The 4th character can be any digit.

    It's pretty simple code like a regular expression with the exception of the exception in the 2.   Here's a way to get around that:

    REGEXP_LIKE (law on the)

    , ' (' || -options for the first 2 digits of start

    "([01][0-9])' |" --0 or 1, followed by another digit

    '| (2[0-3])'    || -2 followed by 0, 1, 2 or 3

    ')'              || -end of the options for the first 2 digits

    '[0-5]'          || -any digit between 0 and 5

    '[0-9]' - a figure

    )

    As others have said, think about the type of data.  How will you use this column?  If you really need a column which reflects a time of day, but not special, then perhaps an INTERVAL, or a NUMBER (for example, the number of hours after midnight) rather than a string.

  • getting bad results with a query

    I have a column with the VARCHAR2 data type name (2) into a table and another table with a column named OFFICER_ZONE with the VARCHAR2 data type (1). What I'm trying to do is to compare these data and then insert it in the second table. But before you insert the data, if the AREA is equal to a number in double digits with a zero in front of her, then I need to CUT 0. If the BOX has a number greater than 9, then I have just these values to NULL. With the query below, I get the upper to 9 zones to be null, which is correct, but I also have those who are the two numbers with a zero not significant, which is not correct.

    For example:
    Area
    1
    2
    5
    07
    15
    19
    14
    6
    02
    d
    c
    e
    b

    Results:
    Bad area: 07
    Bad box: 15
    Bad area: 19
    Bad box: 14
    Bad area: 02

          --ZONE BAD DATA
          IF CR.ZONE NOT IN ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u',
              'v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
              '0','1','2','3','4','5','6','7','8','9')
          THEN
              V_OFFICER_ZONE := NULL; 
              DBMS_OUTPUT.PUT_LINE('ZONE NOT VALID:'||CR.LOCCASENUM||CR.ZONE);
              insert into pursuits.pursuit_exception(case_number,table_name,error_message)
              values(cr.loccasenum,'PURSUIT','Bad Zone: '||v_officer_zone||','||cr.zone);
          ELSE
              V_OFFICER_ZONE := TRIM(LEADING 0 FROM CR.ZONE);
          END IF;
    with t as (
               select '1' zone from dual union all
               select '2' from dual union all
               select '5' from dual union all
               select '07' from dual union all
               select '15' from dual union all
               select '19' from dual union all
               select '14' from dual union all
               select '6' from dual union all
               select '02' from dual union all
               select '0' from dual union all
               select '00' from dual union all
               select 'd' from dual union all
               select 'c' from dual union all
               select 'e' from dual union all
               select 'b' from dual
              )
    select  zone,
            case
              when length(zone) = 1
                then zone
              when zone between '00' and '09'
                then substr(zone,2)
              else null
            end officer_zone
      from  t
    /
    
    ZONE OFFICER_ZONE
    ---- ------------
    1    1
    2    2
    5    5
    07   7
    15
    19
    14
    6    6
    02   2
    0    0
    00   0
    
    ZONE OFFICER_ZONE
    ---- ------------
    d    d
    c    c
    e    e
    b    b
    
    15 rows selected.
    
    SQL> 
    

    SY.

  • records with an outer join restrictions while using a sub query?

    I have the following code:

    declare

    Default char Activeonly ' n ';

    SearchKey varchar2 (15) default '413041494500064';

    number of lclAcctNo;

    Start

    Select

    rat_acct_no in lclAcctNo

    ACCT,.

    marketer_account ma1,

    Marketing agent,

    Account_Service,

    Account_Address

    Where (Rat_Acct_No = Mka_Acct_No

    and Mka_Exp_Dt = (ma2 select Max (Mka_Exp_Dt) of Marketer_Account

    Where Mka_Acct_No = Rat_Acct_No)

    and mka_service_type = 'E')

    And Rat_Acct_No = Acs_Acct_No

    And Rat_Acct_No = Add_Acct_No

    "And Add_Address_Type s ="

    And Rat_Full_Css_Acct_No as Trim (Searchkey) | '%'

    And (Activeonly is Null or Activeonly = ' or (Rat_Acct_Status_Cd = 'A' or Rat_Acct_Status_Cd is Null))

    and rownum < 1000;

    dbms_output.put_line ('Account' | lclAcctNo);

    end;

    I'm doing the table MARKETER_ACCOUNT (MKA_fields) an outer join, because the data I expect to will not be on the table, but I want even when the table of ACCT.

    I can't do an outer join on subqueries, so wanted to know if there was a way more easy/better to Edifier cela?

    I use Oracle 11.2 g.

    Thanks for any help.

    Sean

    Basically, I think, your outer join is ruined by the subquery correlated in the WHERE clause:

    R.ToDate = (Select MAX(ToDate) from R r2
    

    Since you joined outside R to A tell you the database to give you the lines of A for which R.ToDate is null * AND * meets your requirement: and this is not possible. Tom Kyte gave the classic explanation for this kind of problem long ago on AskTom: http://asktom.oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:4963137609733 ("ask yourself this - how a row in T2 (EMP in your example) the MISSING two (composed due to the outer join) AND have a column that corresponds to something?")  It cannot be").

    Here's your example in DDL + DML form: ''

    create table account)

    VARCHAR2 (10) key

    , name varchar2 (10)

    , status varchar2 (10)

    );

    insert into account values ('A1', 'John', 'Active');

    insert into account values ('A2', 'Mary', 'Active');

    insert into account values ('A3', 'James', 'Inactive');

    Create array of marketing)

    VARCHAR2 (10) key

    , Varchar2 (10) Mktr

    );

    insert into values Marketer ("M1", "ABC");

    insert into values Marketer ("M2", "DEF");

    create table relationship)

    VARCHAR2 (10) key

    , Varchar2 (10) AccKey

    , MktKey varchar2 (10)

    , FromDt varchar2 (10)

    , Varchar2 (10) so far

    );

    insert into the relationship values ('R1', 'A1', 'M1', "" 01/01/2012 ', December 31, 2012 ' ");

    insert into the relationship values ('R2', 'A1', 'M2', "01/01/2013 ', 'present'");

    insert into the relationship values ('R3', 'A2', 'M2', ' 01 /' 02/2013, 31 / 05/2013 ');

    Select B.SID

    M.Mktr

    R.FromDt

    R.ToDate

    account A

    left join

    relationship R

    on (a.Key = R.AccKey)

    left join

    Distributor M

    on (R.MktKey = M.Key)

    where R.ToDate = (Select MAX (r2. To date)

    relationship r2

    where r2. AccKey = A.Key)

    and A.Status = 'Active '.

    ;

    MKTR FROMDT NAME DATE

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

    Mary DEF 2/1/2013 5/31/2013

    John DEF 01/01/2013 presents

    -a possibility to obtain all the relevant lines would be to perform filtering after the join:

    with

    BaseData as)

    Select B.SID

    A.key

    M.Mktr

    R.FromDt

    R.ToDate

    account A

    left join

    relationship R

    on (a.Key = R.AccKey)

    left join

    Distributor M

    on (R.MktKey = M.Key)

    )

    Select basedata.*

    of basedata

    where basedata. ToDate = (Select MAX (r2. To date)

    relationship r2

    where r2. AccKey = basedata. Key)

    or basedata. This day is null;

    KEY MKTR FROMDT NAME DATE

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

    Mary A2 DEF 2/1/2013 5/31/2013

    John A1 DEF 01/01/2013 presents

    James A3

    Of course, there are many other possible solutions - since it's SQL...

    Concerning

    Martin

  • Using Left Outer Join with reference

    I have three tables.
    Table 1: BOOK_DETAILS
    Fields: BOOK_ID, BOOK_NAME

    Table 2: BOOK_ISSUE_RECORD
    Fields: BOOK_ID, USER_NAME

    Table 3: BOOK_AUTHOR
    Fields: BOOK_ID, AUTHOR_NAME

    I must link table 1 and table 2 with a left outer join, because even if the book is not the questions to anyone, his name should come.
    I have once again display the name of the author of books for each book.
    I am able to create a query with the left outer join between table 1 and table 2. However, I am not able to give a reference to Table 3.
    Can someone help me with this please.

    Concerning
    Hawker
    select  d.book_name,
            a.book_author,
            i.user_name
      from       book_details d
            join
                 book_author a
              on (d.book_id = a.book_id)
            left join
                 book_issue_recors i
              on (d.book_id = i.book_id)
    /
    

    SY.

  • Create a view which limits a large table, but also allows an outer join?

    Oracle 10.2.0.4

    CREATE TABLE MY_PAY_ITEMS

    (EMP VARCHAR2 (8) NOT NULL)

    , PAY_PRD VARCHAR2 (8) NOT NULL

    , KEY1 VARCHAR2 (8) NOT NULL

    , KEY2 VARCHAR2 (8) NOT NULL

    , LN_ITEM VARCHAR2 (4) NOT NULL

    , ITEM_AMT NUMBER (24.2) NOT NULL

    VARCHAR2 (100) FILL NON-NULL)

    INSERT INTO MY_PAY_ITEMS

    SELECT A.EMP

    B.PAY_PRD

    C.KEY1

    D.KEY2

    E.LN_ITEM

    F.ITEM_AMT

    , '                      '

    FROM (SELECT TO_CHAR (ROWNUM, ' 00000000') 'EMP' FROM DUAL CONNECT BY LEVEL < = 50) has

    , (SELECT '2010-' |) To_char(rowNum,'00') 'PAY_PRD' FROM DUAL CONNECT BY LEVEL < = 52) B

    , (SELECT TO_CHAR (ROWNUM, ' 000') 'KEY1' FROM DUAL CONNECT BY LEVEL < = 8) C

    , (SELECT TO_CHAR (ROWNUM, ' 000') 'Key2' FROM DUAL CONNECT BY LEVEL < = 5) D

    , (SELECT TO_CHAR(ROWNUM,'000') 'LN_ITEM' FROM DUAL CONNECT BY LEVEL < = 20) E

    (round (DBMS_RANDOM. VALUE * 400.2) "ITEM_AMT" of the double) F

    CREATE A UNIQUE INDEX MY_PAY_ITEMS ON MY_PAY_ITEMS (MEP, PAY_PRD, KEY1, KEY2, LN_ITEM)

    CREATE TABLE MY_ITEM_DISPLAY

    (THE VARCHAR2 (4) OF DISPLAY_CODE NOT NULL)

    , NUMBER (2) SEQUENCE NON-NULL

    , COLUMN_ITEM1 VARCHAR2 (4) not null

    , COLUMN_ITEM2 VARCHAR2 (4) not null

    , COLUMN_ITEM3 VARCHAR2 (4) not null

    COLUMN_ITEM4 VARCHAR2 (4) not null)

    INSERT INTO MY_ITEM_DISPLAY VALUES ('01 ', 10, '001', '003', '004',' 005');

    INSERT INTO MY_ITEM_DISPLAY VALUES ('01 ', 20 '007', '013', '004',' 009');

    INSERT INTO MY_ITEM_DISPLAY VALUES ('01', 30 ' 001', '004', '009',' 011');

    INSERT INTO MY_ITEM_DISPLAY VALUES ('01', 40, '801 ', ' 304 ', 209',' 111');

    INSERT INTO MY_ITEM_DISPLAY VALUES ('02 ', 10, '001', '003', '004',' 005');

    INSERT INTO MY_ITEM_DISPLAY VALUES ('02 ', 20 '007', '013', '004',' 009');

    INSERT INTO MY_ITEM_DISPLAY VALUES ('02', 30 ' 001', '004', '009',' 011');

    MY_PAY_ITEMS is a table that stores line of payslip items.  It has a total area of 500,000,000 lines.

    PEM is the unique id, we have about 200,000 employees (with about 50,000 being active today).

    PAY_PRD is a weekly pointer (2010-01, 2010-02, 2010-52), we have the 2004 data and add a new pay period each week.  2010 01 is defined as the first Monday in 2010 for the first Sunday in 2010, etc.

    Key1 is an internal key, it follows the chronology in the pay period.

    KEY2 is a child of KEY1, there follows the sequence of events in KEY1.

    LN_ITEM is the component of actual compensation resulting from the event, on average, a person produces 20 lines per event.  Note that in this example, everyone gets the same LN_ITEM values, but in practice it is selected 20 of 300

    ITEM_AMT is the net salary per command line.

    FILLING is a set of fields that are unrelated to this issue, but act as a brake on the charges of the line.

    MY_ITEM_DISPLAY is an array that describes how some screens should display items.  The screen itself is a grid of 4 poles, with the content of each cell is defined as a LN_ITEMS search to retrieve the relevant LN_AMT.

    We have an application that receives a DISPLAY_CODE and an EMP.  It automatically creates an sql statement in the sense of

    SELECT * FROM MY_VIEW WHERE DISPLAY_CODE =: 1 AND EMP =: 2

    and returns the output to the user.

    My challenge is that I need to rewrite MY_VIEW as follows:

    (1) (select the relevant lines from MY_ITEM_DISPLAY where DISPLAY_CODE =: 1)

    (2) select the relevant all MY_PAY_ITEMS lines that meet the criteria

    (a) EMP =: 2

    (b) PAY_PRD = (a more recent for EMP and sysdate, so if he got last paid 2010-04, return 2010-04)

    (c) KEY1 = (highest key1 in EMP and PAY_PRD)

    (d) KEY2 = (highest key2 in KEY1, PAY_PRD and EMP)

    (3) I then need to cross reference to create tabular output

    (4) Finally, I have to return a 0 line where there is no LN_ITEMs (DISPLAY_CODE 01, 40 sequence contains possible values for this scenario)

    The following query is part of it (but not the PAY_PRD, KEY1, KEy2)

    Select * from)

    SELECT A.DISPLAY_CODE

    B.EMP

    A.SEQUENCE

    , MAX (DECODE (B.LN_ITEM, A.COLUMN_ITEM1, B.ITEM_AMT, 0)) 'COL1 '.

    , MAX (DECODE (B.LN_ITEM, A.COLUMN_ITEM2, B.ITEM_AMT, 0)) 'COL2 '.

    , MAX (DECODE (B.LN_ITEM, A.COLUMN_ITEM3, B.ITEM_AMT, 0)) 'COL3 '.

    , MAX (DECODE (B.LN_ITEM, A.COLUMN_ITEM4, B.ITEM_AMT, 0)) 'COL4 '.

    OF MY_ITEM_DISPLAY A, MY_PAY_ITEMS B

    WHERE B.PAY_PRD = ' 2010-03'

    GROUP OF A.DISPLAY_CODE, B.EMP, A.SEQUENCE)

    WHERE DISPLAY_CODE = '01'

    AND EMP = '0000011'

    SEQUENCE ORDER

    My questions

    (1) how I do PAY_PRD, KEY1, KEY2 forced, can I use a form any of ROW_NUMBER() FUNCTION?

    (2) how can I deal with the fact that none of the 4 LN_ITEMS column can exist (see sequence 40, none of these can exist)...  Ideally the SQL above should return

    01, 0000011, 10, < a digit - > < number > - < a digit - > < some number >

    01, 0000011, 20, < a digit - > < number > - < a digit - > < some number >

    01, 0000011, 30, < a number--> < number > - < number > - < number > -

    01, 0000011, 40, 0, 0, 0, 0

    I tried a UNION, but it prevented the view to eliminate most of the MY_PAY_ITEMS lines, because it solves ALL MY_PAY_ITEMS instead of simply retrieve lines for the EMP passed to the view.  The same seems to be true for outer joins.

    Hi Paula,

    It does not handle SEQNUM 40, it's just that your second set of test data did not SEQNUM 40. When I put in the first set of values MY_ITEM_DISPLAY, I get:

    DISP EMP SEQUENCE COL1 COL2 COL3 COL4

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

    01 00000011 10 101.1 103.1 105.1 104.1

    01 00000011 20 107.1 113.1 104.1 109,1

    01 00000011 30 101.1 104.1 109.1 99.99

    01 00000011 40 0 0 0 0

    If this isn't the issue, you will need to explain the requirement of "outer join" and what you want more. Apart from his return nothing if there is absolutely no element of remuneration of the employee, this query will always return a line for each line MY_ITEM_DISPLAY for the display_code. If there is absolutely no data, no return line seems reasonable.

  • OUTER JOIN query returns the results of JOIN IN-HOUSE 11.2.0.1.0

    I'm data transfer in 11.2.01.0 (Windows XP 32-bit) and I wanted to compare the sizes of table with the same Table name in two different patterns, ML and SILENT, with a FULL OUTER JOIN (to account for all the tables and NULL values in a diagram).

    The scheme of ML has 176 tables: schema TUT a 133 tables. The use of a standard INNER JOIN gives 131 paintings.

    I get precisely the results with a FULL OUTER JOIN I get with an INTERNAL JOIN (not the same NULL values so I know they exist).

    This happens in SQL-Plus, SQL_Developer and using Oracle Wire pilot of Data_Direct.

    Here is the code:

    Login: SYS as SYSDBA or SYSTEM (same results for either)

    SELECT M.TABLE_NAME, M.NUM_ROWS, T.TABLE_NAME, T.NUM_ROWS
    OF SYS. ALL_TABLES M FULL OUTER JOIN SYS. ALL_TABLES T ON M.TABLE_NAME = T.TABLE_NAME
    WHERE
    M.OWNER = 'ML' AND
    T.OWNER = 'TUT';

    Produce the same results with LEFT OUTER joins and RIGHT OUTER joins in ASI and Oracle (+) syntax.

    Any thoughts?

    Hello

    If you read what I posted, forget it. MScallion (below) gave the correct answerr.

    If conditions such as

    owner   = 'ML'
    

    in the WHERE clause, and then they will reject the rows of the result set formed by the join condition.

    The inner join returns only 131 lines where the two 'paintings' have the same table_names.
    The outer joins return multiple lines (133, 176 or 178) before the place WHERE the provision is applied , but the WHERE clause eliminates all lines except the 131 found by the inner join.

    Published by: Frank Kulash, July 10, 2010 14:23

Maybe you are looking for