Outer join or a function of the level line

Hi all

I have a question which involves five tables T1, R1, R2, R3, and R4. T1 is an operating table, while R1, R2, R3, and R4 are tables of references (tables parent, with the foreign keys defined in T1). Table T1 contains always referenced data R2 and R1. BUT table T1 can sometimes contain NULL for R3 and R4.

Now my question is simple;
Should I use an OUTER Join for R3 and R4 in the query? as

< code >
Select T1.col1, R1.col2, R2.col2, R3.col2, R4.col2
T1, R1, R2, R3, R4
where T1.col2 = R1.col1
and T1.col3 = R2.col1
and T1.col4 = R3.col1 (+)
and T1.col5 = R4.col1 (+)
< code >

OR

Can I use level functions online for R3 and R4, as

< code >
Select T1.col1, R1.col2, R2.col2,
(Select R3.col2 in R3 where R3.col1 = T1.col4),
(Select R4.col2 in R4 where R4.col1 = T1.col5)
T1, R1, R2
where T1.col2 = R1.col1
and T1.col3 = R2.col1
< code >

Which approach is better and why?

Records in T1 = 2 000 000
R1 = 1000 records
Records in R2 = 300
Records in R3 = 1800
Records in R4 = 200

Please note that all foreign keys are indexed, there are primary keys for all the tables in R

Thank you
QQ.

According to the 'official' documentation the outer join should be the by far best choice, because I still think the Oracle documentation says that the subquery will be executed for each row of the main query.

But the Oracle execution engine is a lot smarter (I think from Oracle 8i) and offers a "Value for the filter" feature supposedly which also applies to the "scalar subqueries" you are talking about to (but only if the subquery is considered to be deterministic, i.e. returns always the same value for the same input value of the main request).

Basically, this Treaty optimization the subquery as a function of an input value (the link to the main request) and an output value (the result of the query) and maintains a hash table in memory of pairs of input/output value. The size of the changes table in memory from one version to the other, I think in 9i, it is set by default to 256 entries but in 10g, it is limited in size and therefore the number of entries depends on the size of the values to store.

The effectiveness of this optimization of memory-search in the table depends on certain factors such as the number of pairs of distinct value, the order of the incoming values and collisions in the table which can be occur according to hash values.

Jonathan Lewis has an in-depth coverage of these mechanism in its "cost-based Oracle: Fundamentals" book.

To make a long story short, since your tables R3 and R4 are relatively low, you might want to give a chance, because these optimizations could work very well in your particular case, but unfortunately the real result is simply unpredictable due to the above constraints, including the order of the incoming values.

Kind regards
Randolf

Oracle related blog stuff:
http://Oracle-Randolf.blogspot.com/

SQLTools ++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676 /.
http://sourceforge.NET/projects/SQLT-pp/

Tags: Database

Similar Questions

  • Bug with an outer join, or &amp; 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)

  • 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

  • Why left outer join with a table gives me more lines?

    Hi gurus,

    I can see "view_a" and a table 'table_a '.

    view_a a county of 100 lines. Now, when I left outer join that discovers with a 'table_a', I expect all 100 lines.

    However, I'm more than 100 lines. Is it still possible?

    Also even to analyze these situations, how can I move forward?

    Because it is very high volumn of sight and takes longer to run.

    Select count (*) view_a, view_b

    where view_a.col1 = view_b.col1 (+)

    and view_a.col2 = view_b.col2 (+);

    Thank you

    I can see "view_a" and a table 'table_a '.

    view_a a county of 100 lines. Now, when I left outer join that discovers with a 'table_a', I expect all 100 lines.

    However, I'm more than 100 lines. Is it still possible?

    Also even to analyze these situations, how can I move forward?

    Because it is very high volumn of sight and takes longer to run.

    Select count (*) view_a, view_b

    where view_a.col1 = view_b.col1 (+)

    and view_a.col2 = view_b.col2 (+);

    Which is not necessarily related to the use of an outer join.

    Just join of two tables in general will give you more rows of one table has.

    Scott DEPT table contains ONE row for deptno = 10

    The EMP table has THREE rows of deptno = 10

    The number of rows you plan if you join two tables using an equi-join?

    Three - what is MORE lines the DEPT table has for deptno = 10

    Select * from Department where deptno = 10

    DEPTNO, DNAME, LOC
    10, ACCOUNTING, NEW YORK

    Select * from emp where deptno = 10

    MGR, EMPLOYMENT ENAME, EMPNO, HIREDATE, SAL, COMM, DEPTNO
    7782, CLARK, MANAGER, 7839, 6/9/1981,2450, 10
    7839, KING, PRESIDENT, 17 NOVEMBER 00, 10
    7934, MILLER, CLERK, 7782, 23 JANUARY 00: 10

    Select dept.*, emp.*
    Department, emp
    where dept.deptno = 10
    and dept.deptno = emp.deptno

    DEPTNO, DNAME, LOC, EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO_1
    10, ACCOUNTING, NEW YORK, 7782, CLARK, MANAGER, 7839, 6/9/1981,2450, 10
    10, ACCOUNTING, NEW YORK, 7839, KING, PRESIDENT, 17 NOVEMBER 00, 10
    10, ACCOUNTING, NEW YORK, 7934, MILLER, CLERK, 7782, 23 JANUARY 00: 10

    So if these are the lines ONLY in the table EMP and DEPT the query would give you THREE lines despite the DEPT table only ONE line.

    No do you expect? You get ALL the child rows that belong to the parent company. Otherwise, how could it possibly work?

    The OUTER join includes lines where the parent row exists but there is NO child line as others have shown.

    Outer joins

    Outer join extends the result of a simple join. Outer join returns all rows that satisfy the join condition and also returns some or all rows in a table for which no line of the other meet the join condition.

    Get more lines to exist in one of the paintings is a basic necessity. It usually has NOTHING to with the question of whether you have an outside to join or not.

    See the section on the JOINTS in the Oracle documentation

    http://docs.Oracle.com/CD/B28359_01/server.111/b28286/queries006.htm

  • FIRST analytical functions returns the null line

    The following query returns a null line when there is no such thing as a line for the predicate. Is it a bug or expected behaviour. If so what is the meaning of the null row, is it not logical?



    SELECT NVL (max (ah.fyr_end_dt) KEEP (DENSE_RANK FIRST ORDER BY ah.as_of_dt DESC), ' RETURNED NULL')
    Of account_history ah
    WHERE
    Ah.acct_id = 999
    AND trunc (ah.as_of_dt) < = 31 December 08 '
    ;

    Hello

    user4900730 wrote:
    Moreover, in my example how I distinguish the case where a line really exists, but the column is null when there is no such thing as a line and the FIRST function returns the same value null? Hopefullly I should be able to do it in a single SQL and know the difference?

    COUNT (*) > 0, but COUNT (col_x) = 0, then there is a line, but col_x happened to be null.

    For example, the following query shows that there is 1 row in the group with the lowest name ("ADAMS"), but the column comm in all ranks of this group is null:

    SELECT     COUNT (*)    KEEP (DENSE_RANK FIRST ORDER BY ename)
                              AS total_cnt
    ,     COUNT (comm) KEEP (DENSE_RANK FIRST ORDER BY ename)
                              AS comm_cnt
    FROM     scott.emp
    ;
    

    Output:

     TOTAL_CNT   COMM_CNT
    ---------- ----------
             1          0
    

    The employee whose highest name ("WARD") has a number in the comm column.

  • Behavior of the TRIGGERS of the LEVEL LINE

    Hello Experts,

    I have an isue with the Trigger sequence.

    in books or on the net I read that the trigger firing order is

    before the declaration

    |

    before the line

    |

    statement (provide the event like insert, update)

    |

    After the rank

    |

    After statement

    .

    but I had different behaviors in the following conditions

    (1) example 1 (my assumption, statement-level trigger works very well)

    I create a table tab_stmt (a key number of priimary)

    I have two triggers on it

    (i) create or replace trigger bef_stmt

    Before Insert on ytab_stmt

    Start

    DBMS... ("before stmt');

    end;

    (II) create or replace trigger aft_stmt

    AfterInsert on tab_stmt

    Start

    DBMS... ("after stmt');

    end;

    When I insert a value in the tab_stmt table

    What value = 10

    My o/p is - before stmt

    After stmt

    When I insert again value = 10 (forcing in the error, and then only prior to the declaration of the trigger, then error)

    o/p is - before stmt

    This means that my explanation is fuine

    (2) but for row level trigger that I did not get a correct output or maybe I'm not theoretically correct.

    example of

    create a table tab_row (a key number of priimary)

    triggers

    (i) create or replace trigger bef_row

    Before Insert on tab_row

    for each line

    Start

    DBMS... ("before the line");

    end;

    (II) create or replace trigger aft_row

    After Insert on tab_row

    for each line

    Start

    DBMS... ("after the line");

    end;

    Now, when I insert value

    (1) insert into tab_row values (10)

    o/p == > before line

    After the rank

    (2) but now twist is here.

    According to me, if I insert again value = 10

    (1) then is should give error but before giving it must first will trigger before row-level trigger

    as I am in the event of the trigger shot as before line-> State-> after the rank

    but when I insert - Insert tab_row (10)

    it fires before row-level trigger, but gives me an error.

    can you please explain this behavior of row-level trigger to make my concept will be clear?

    Thanks in advance

    Hello

    It works fine for me.

    I created the table and triggers exactly as you posted.

    The I ran this:

    FAST = 1 INSERT =.

    INSERT INTO tab_row (a) VALUES (10);

    FAST = 2ND INSERTION =.

    INSERT INTO tab_row (a) VALUES (10);

    The output I got was:

    = 1 INSERT =.
    line of BEF
    back row

    1 line of creation.

    = 2ND INSERTION =.
    line of BEF
    INSERT INTO tab_row (a) VALUES (10)
    *
    ERROR on line 1:
    ORA-00001: unique constraint (SYSTEM. SYS_C00121927) violated

    As you can see, "bef row" appears right before the error has been reported.

    What software do you use?  I tried this on 12.1.0.1.0, Oracle with SQL * Plus 11.2.0.1.0.

  • Restoration of the level line

    Hi experts,

    uses jdeveloper11.1.1.5.0 - adfbc - oracle db10g.

    I need line-level restore operation. is it possible to achieve that?

    Check [url http://www.oracle.com/technetwork/developer-tools/adf/learnmore/06-cancelform-java-169125.pdf] how to cancel an edit form, cancelling the changes in Java

  • Select the query with the level line list where the clause

    Hi all

    I am creating a tabular presentation based on a SQL query that has a list of selection based on a query with a where clause clause that refers to a column in the original SQL query.

    The situation is, I have a table that stores the client_id, source_id, and build_id, lets call it client_source. I have a second table, build_source, containing source_id and build_id, one to many relations between the two (1 source_id could have build_id 1-7).

    Using a tabular presentation, I want to select the correspondent build_id to use in client_source, but the selection list should contain only the build_id for this particular source_id of lines.

    Here is an example of the SQL source of tabular presentation;

    Select
    s.ROWID,
    s.CLIENT_ID,
    s.SOURCE_ID,
    APEX_ITEM. SELECT_LIST_FROM_QUERY (1, s.BUILD_ID,)
    "Select display b.build_id, b.build_id return.
    b build_source where b.source_id = s.SOURCE_ID ') lst
    of s client_source

    what I want to achieve, it's as source_id "BOLD" match fields. When the query is built this way, I get an error of "invalid identifier" Oracle on s.SOURCE_ID during execution.

    Is there some special tags to be used to refer to the external column? I must be missing something because this looks like a pretty mundane problem.

    I am running on 4.1.0.00.32, on an Oracle 10 g release 10.2.0.4.0 Server Express request.


    I look forward to useful responses!


    See you soon,.
    Jason

    Published by: 1005131 on May 9, 2013 19:02

    Your selection by query list receives a static SQL. That SQL can't "see" the value of your s.source_id.
    But it would work like this:
    where b.source_id = ' | s.SOURCE_ID)

    You would be the value for the SQL concatenation. It is not ideal, but it will work.

    Jorge

  • How to disable Lov when the value of the attribute is NULL at the level line

    Hi all

    JDev 11.1.1.5.0

    I have a view as a table ADF jsff page object. Value of the attribute in a row may have null values.
    And I want that Lov must be disabled when the value of the attribute in the row is null or not.
    So please suggest me how can I implement this.

    Kind regards
    Marie-Claude

    Set to the disabled for LOV attribute property

    disabled="#{bindings.YourAttribute.inputValue eq null}
    {code}                                                                                                                                                                                                                                        
    
  • Import bills AP and corresponding to a PO and receipt to the level line

    We want to analyze the details of the Bill in a flat file and load them into Oracle and perform it guarantor to the extent possible. Is the best way to do this, use AP_IMPORT_INVOICES_PKG to load the tables ap_invoice_lines_interface and ap_invoices_interface? If so, is the Oracle XML Gateway, the best way to load them?

    Yes it is the right way to use open interface... See the following link & notes MOS.
    http://docs.Oracle.com/CD/A60725_05/HTML/comnls/us/AP/openimpt.htm
    Payables open Interface import [ID 1355939.1]
    Payables open Interface import frequently asked Questions (FAQ) [ID 107617.1]

    Use SQL Loader to load data into the tables of the interface
    http://docs.Oracle.com/CD/A60725_05/HTML/comnls/us/AP/openin05.htm#n_sqlload_open
    Kind regards

  • show on a monthly basis, using the outer join

    Hello

    I use an example of emp table to describe my problem here

    I made a request that is group by hiredate months and showing the sum of wages.

    as follows,

    Select
    TO_DATE (to_char(HireDate,'MON-RRRR'), MON-RRRR), sum (sal)
    Of
    EMP
    Group by
    TO_DATE (to_char(HireDate,'MON-RRRR'), MON-RRRR)
    SQL > /.

    TO_DATE (T SUM (SAL)
    --------- ----------
    FEBRUARY 1ST, 10 21000
    MARCH 1, 10 30000
    MAY 1, 10 43000
    1ST JUNE 10 70000

    what I want is to show also the months too where any recruitment made
    as
    month sum (sal)
    January 1 10 0
    FEBRUARY 1ST, 10 21000
    MARCH 1, 10 30000
    April 1, 10 0
    MAY 1, 10 43000
    1st June 10 0
    1ST JUNE 10 70000
    August 1 10 0
    0 01-sept.-10
    1 October 10 0
    1 November 10 0
    1 December 10 0

    I've tried doing another table with month AND use outer join, but failed to get the result

    any ideas will be appreciated

    Change the following query accordingly as directed by your data

    Select
    ADD_MONTHS (to_date (January 1, 2001 "," dd-MON-RRRR'), level - 1) MonthName
    Of
    Double
    connect by level<=>

    It gives data for 2001
    If your emp table is to have 2010 data while it was being replaced by add_months (to_date (January 1, 2010 "," dd-MON-RRRR'), level - 1) MonthName

    Alexander gelin
    http://nimishgarg.blogspot.com

    Edited by: Caroline Geffroy 10 June 2010 18:11

  • He had to know the right outer join using...

    He had to know the right outer join using...

    For example: first query left outer join for the emp table: SELECT EMPNO, ENAME, D.DEPTNO FROM EMP E, Department D WHERE the E.DEPTNO = D.DEPTNO)

    Second query left outer join for the Dept table: SELECT EMPNO, ENAME, D.DEPTNO FROM EMP E, Department D WHERE the D.DEPTNO = E.DEPTNO)

    In the example above I just Exchange where condition condition to get an outer join of two table with a left outer join itself. Wat is use right outer join, instead, I can swap the status of table name for the result. Please suggest...

    Hello

    chan001 wrote:

    He had to know the right outer join using...

    For example: first query left outer join for the emp table: SELECT EMPNO, ENAME, D.DEPTNO FROM EMP E, Department D WHERE the E.DEPTNO = D.DEPTNO)

    Second query left outer join for the Dept table: SELECT EMPNO, ENAME, D.DEPTNO FROM EMP E, Department D WHERE the D.DEPTNO = E.DEPTNO)

    In the example above I just Exchange where condition condition to get an outer join of two table with a left outer join itself. Wat is use right outer join, instead, I can swap the status of table name for the result. Please suggest...

    The two examples above use the old syntax outer join of Oracle. (I guess there should be a sign inside the parentheses, e.g.. +)

    ...  WHERE E.DEPTNO = D.DEPTNO (+)

    )

    The LEFT OUTER JOIN and RIGHT OUTER JOIN terms apply only to the ANSI join syntax, e. g.

    .

    .. FROM EMP E

    DEPT LEFT OUTER JOIN D ON E.DEPTNO = D.DEPTNO

    As Blushadow said above, there's no real point in having LEFT OUTER JOIN and RIGHT OUTER JOIN;  What you can do with one (or a combination of both) can be done with the other.  Most people use LEFT OUTER JOIN systematically and never use RIGHT OUTER JOIN.

    There are situations where using a combination of the two would mean a little less striking, but only a little less and this kind of situation is very common, and one may wonder if the somewhat shorter code is more specific.  I suggest that forget you RIGHT OUTER JOIN.

  • Suggestion: functions to the package level assert at least grabbing FlexUnit 4

    AS3 is not as nice as Java 5 imports static method, but we can do the same thing with functions at the level of the package. We could use these to reduce the amount of typing required FlexUnit 4.

    I added this to my fork of AsUnit:

    http://github.com/robertpenner/AsUnit/commit/bdb293436491792625ddc1f637c81c723986b87d

    Example:

    package AsUnit . says {
    Import AsUnit . framework . Assert ;
    public const assertEquals : function = Assert . assertEquals ;
    }

    In the test case, this would be used as follows:

    Asunit.asserts import. *;
    ...
    in the test method
    assertEquals (...

    I totally agree with you. I wish we had static imports as well.

    We will talk more about your suggestion, I am certainly open to it.

  • 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

  • How to specify an outer join in the query designer

    I quickly built a large query with the query designer, and it works very well, but does not produce 9 disks on 2200 - so I need to change to an outer join.

    My problem is that I can't find a way to specify an outer join. I tried to change the query, query builder formed, but it won't let me.

    I know that I can capture the query, edit and run it in sql developer and that works fine, but I want to use the Query Builder as it is the fastest way I know to quickly add and remove items - my users don't know exactly what that it to include.

    I know it's kind of a trivial question, but I searched the forum, manual, the web and no luck

    Thanks for any help you can give

    Glenn

    Hi Glenn,.

    When you use the query designer to create the sql statement, you must click on the empty box to the right of the fields in each table to create the join. When you are finished, you should see a line drawn between the two tables. Click on this line, and a small window appears allowing you to select inner outer or right outer joins, left.

    When the report was created, however, you must change the statement. For example, if you use the query designer to join DEPT at EMP based on the DEPTNO field on the two tables, you get:

    select      "DEPT"."DEPTNO" as "DEPTNO",
          "DEPT"."DNAME" as "DNAME",
          "DEPT"."LOC" as "LOC",
          "EMP"."EMPNO" as "EMPNO",
          "EMP"."ENAME" as "ENAME",
          "EMP"."JOB" as "JOB",
          "EMP"."MGR" as "MGR",
          "EMP"."HIREDATE" as "HIREDATE"
     from      "EMP" "EMP",
          "DEPT" "DEPT"
     where   "DEPT"."DEPTNO"="EMP"."DEPTNO"
    

    This is to change:

    select      "DEPT"."DEPTNO" as "DEPTNO",
          "DEPT"."DNAME" as "DNAME",
          "DEPT"."LOC" as "LOC",
          "EMP"."EMPNO" as "EMPNO",
          "EMP"."ENAME" as "ENAME",
          "EMP"."JOB" as "JOB",
          "EMP"."MGR" as "MGR",
          "EMP"."HIREDATE" as "HIREDATE"
     from      "EMP" "EMP"
          LEFT OUTER JOIN "DEPT" "DEPT" ON "DEPT"."DEPTNO"="EMP"."DEPTNO"
    

    Andy

Maybe you are looking for

  • Laptop of HP ENVY TS m7: keys brightness &amp; Graphics Card does not work

    I've refreshed recently my PC in the last month, and after a recent update, my Windows computer has stopped responding to orders of brightness and is stuck at full intensity. In addition, it seems that a common measure of troubleshooting is to instal

  • 60 seconds Lag Spike Vista

    Anyone know if microsoft has released a fix. For those who do not know the question.  First of all, I have disabled wireless.  During the game, as every 60 seconds vista looks for a better connection, however doing so creates a huge lag spike.  That

  • Impossible to reformat the computer after the OEM disc error: check the model number.

    Original title: Updated Windows and now I can't reformat my Sony Vaio... why? I have a Sony Vaio VGN-NR110E, only thing replaced was the battery, so no problem of "tattoo", but the software, discs and OEM disks say "check model number", won' t reform

  • Windows Movie Maker is unable to load YouTube - error is 0 x 80131620

    Using Windows Home Premium Version 6.1 Build 7601 Service Pack 1 if this is useful. You use Windows Movie Maker to transfer a wmv to cd on YouTube. Charges, publishes 99%, then the logging of error is 0 x 80131620 me. Impossible to find a solution. W

  • Web page display 'cannot display this page' not

    Hi - regular problems when trying to book tickets online etc - details are entered and submitted - pending the outcome "cannot display this page, check web address is correct, look for the page with your search engine, refresh the page in a few minut