One-to-many outer join in MView, is possible?

Re: 10g R2
Is it simply not possible to have fast refresh on outer joins that are 1-to-many relations? I have in this script a unique key addition to "fix" it, but it restricts something that I don't want restricted. If indeed this is how it should work, are there any strategies for improving performance for queries on this type of thing? The "fact_table" in this example is actually another materialized view with simple inner joins, so that works perfectly, but I was trying to improve query performance in this case too.
Run the script w/ dbms output...all self contained within the schema.
drop materialized view log on fact_Table;
drop materialized view log on outer_detail;
drop materialized view mview_test;
drop table outer_detail cascade constraints;
drop table fact_Table cascade constraints;
create table fact_table (myid number primary key, fact_attrib varchar2(10));
create table outer_detail (myid number primary key, outer_attrib varchar2(19), fact_table_id number, constraint fk_outer_to_Fact foreign key (fact_table_id) references fact_table(myid));
CREATE MATERIALIZED VIEW LOG ON fact_table WITH ROWID;
CREATE MATERIALIZED VIEW LOG ON outer_detail WITH ROWID;
declare
    v_capabilities sys.ExplainMVArrayType ;
begin
    dbms_mview.explain_mview('SELECT ft.rowid "ftrid", ' ||
       'od.rowid "odrid", ' ||
       'ft.myid fact_id, ' ||
       'od.myid outer_id, ' ||
       'ft.fact_attrib, ' ||
       'od.outer_attrib ' ||
  'FROM fact_table ft, outer_detail od ' ||
'WHERE ft.myid = od.fact_table_id (+)', v_capabilities);
        dbms_output.put_line('ATTEMPT 1:');
        dbms_output.put_line('==============================================');
    for v_capability in (select capability_name, possible, related_text, msgtxt from table (v_capabilities))
    loop
        dbms_output.put_line('==============================================');
        dbms_output.put_line('==============================================');
        dbms_output.put_line(v_capability.capability_name);
        dbms_output.put_line(v_capability.possible);
        dbms_output.put_line(v_capability.related_text);
        dbms_output.put_line(v_capability.msgtxt);
    end loop;
end;
/*CREATE MATERIALIZED VIEW mview_test
PARALLEL BUILD IMMEDIATE
REFRESH FAST ON COMMIT WITH ROWID
AS
SELECT ft.rowid "ftrid",
       od.rowid "odrid",
       ft.myid fact_id,
       od.myid outer_id,
       ft.fact_attrib,
       od.outer_attrib
  FROM fact_table ft, outer_detail od
WHERE ft.myid = od.fact_table_id (+);
-- I'd like it to run without this constraint, is it not possible?
alter table outer_detail add constraint unk_outer_detail unique (fact_table_id);
declare
    v_capabilities sys.ExplainMVArrayType ;
begin
    dbms_mview.explain_mview('SELECT ft.rowid "ftrid", ' ||
       'od.rowid "odrid", ' ||
       'ft.myid fact_id, ' ||
       'od.myid outer_id, ' ||
       'ft.fact_attrib, ' ||
       'od.outer_attrib ' ||
  'FROM fact_table ft, outer_detail od ' ||
'WHERE ft.myid = od.fact_table_id (+)', v_capabilities);
        dbms_output.put_line('');
        dbms_output.put_line('');
        dbms_output.put_line('');
        dbms_output.put_line('ATTEMPT 2:');
        dbms_output.put_line('==============================================');
    for v_capability in (select capability_name, possible, related_text, msgtxt from table (v_capabilities))
    loop
        dbms_output.put_line('==============================================');
        dbms_output.put_line('==============================================');
        dbms_output.put_line(v_capability.capability_name);
        dbms_output.put_line(v_capability.possible);
        dbms_output.put_line(v_capability.related_text);
        dbms_output.put_line(v_capability.msgtxt);
    end loop;
end;
/Edited by: ORA-01435 on Sep 30, 2009 12:54 PM

That's what I thought too. As far as I'm concerned, this is perfectly acceptable. Of course I'm in 10g R2, but:
http://download.oracle.com/docs/cd/B19306_01/server.102/b14223/basicmv.htm#sthref534
I keep re-reading the rules, trying to see why it thinks I'm violating one of them. Might have to meta-link this one.
Just ran this on a different box, ran fine. Seem to have configuration issues between the boxes.
Edit: Just determined that the boxes that this doesn't work on have Oracle parameters for compatibility set to 10.1.0.2.0, I'll change them and check if it modifies behavior
Edited by: ORA-01435 on Oct 1, 2009 7:44 AM

Similar Messages

  • One to Many table join -- concat field per record grouped by id

    Post Author: wm5
    CA Forum: Formula
    Hello,
    I am using Crystal Reports XI and have two tables that have a one to many relationship and are joined by an JobID (number).
    Below is a sample with relative fields for each table.
    job_table: JobID (number), Manager (text), Status (text)
    jobaudit_table : JobAuditID (number), JobID (Number), FormID (Number)
    There is a one to many relationship with jobaudit_table having multiple records for each JobID in job_table.
    I have created a Group Header using the job_table.JobID and suppressed the detail section.
    In the group header for each JobID I display the JobID, Manager, Status. I also use the below formula to determine if any records in the jobaudit_table has a record where FormID = 90. If so, I display "Yes". If not, "No".
    So my report currently looks like.
    JobID     Manager     Status     Audit Performed
    1           Manager 1  Closed           N
    2          Manager 2   Closed           Y
    Here are the formula's I use to determine if any records in jobaudit_table contains a record where FormID = 90.
    @ja90exists
    if {jobaudit_table.FormID} = 90 then    1else    0;
    if sum({@ja90exists},{job_table.JobID}) = 0 then    "No"else    "Yes";
    Everything so far works fine. What I would like to do now is add a hyperlink to a script to view the job audit when in the above report the "Audit Performed" column is "Yes"
    So Report is now:
    JobID     Manager     Status     Audit Performed
    1           Manager 1  Closed           N
    2          Manager 2   Closed           Y (hyperlink to view audit)
    I cannot figure out how to gather the valid JobAuditIDs where FormID = 90 grouped by JobID to be used in the Group Heading section of the report.
    Also, it is unlikely, but possible that more than one job_audit record exists with FormID = 90 per JobID. So, my hyperlink could look like http://mysite.com/viewjobaudit.aspx?jobid=[jobaudit_table.JobAuditID],[jobaudit_table.JobAuditID] .
    Thanks for any help. And if this post is not clear let me know and I will clarify.
    wm5

    Post Author: bettername
    CA Forum: Formula
    Although I can't think of a way to get multiple hyperlinks, this should be a start.  It (should) hyperlink to the last job/audit in the group that formID of 90.  Oh, I assumed that the hyperlink should have been  xxxx...jobID,jobAuditID! 
    I think there may be a way of getting hyperlinks to every "90" record, but that will involve a subreport, so lets try this first...
    1 - everything from your group header to the group footer...
    2 -  add a formula into the group header that says:
    whileprintingrecords;
    stringvar jobauditID="";
    stringvar jobID:=";
    3 - Then add a formula to the details section:
    whileprintingrecords;
    stringvar jobauditID;
    stringvar jobID;
    if {jobaudit_table.FormID} = 90
    then (jobID:=totext({job_table.job_id},0,""); jobauditID:=totext({jobaudit_table.jobaudit_id},0,"")
    4 - Finally, on your "Audit Performed" formula, have a conditional hyperlink that says:
    whileprintingrecords;
    stringvar jobauditID;
    stringvar jobID;
    if {@audit performed} = "Y" then http://mysite.com/viewjobaudit.aspx?jobid=jobID","+jobauditID

  • Unidirectional one-to-many with join table

    According to http://docs.jboss.org/hibernate/orm/3.5/reference/en-US/html/associations.html#assoc-unidirectional-12m "A unidirectional one-to-many association on a foreign key is an unusual case, and is not recommended", instead they recommend using a join table, e.g.
    create table Person ( personId bigint not null primary key )
    create table PersonAddress ( personId not null, addressId bigint not null primary key )
    create table Address ( addressId bigint not null primary key )
    However if doing this, when using SQLDeveloper the Address table does not appear as a child table of Person, which it should be as a unidirectional one-to-many meaning that I can't create a cache group for Person and subsequently Person.
    Is this something that can be worked around as I'm using a legacy schema created from Hibernate/JPA and the implications of changing are quite substantial?
    Thanks

    Hi Gennady,
    Apologies but my question was not clear enough. The schema structure that I have inherited is as follows:
    CREATE TABLE T_PERSON ( PERSONID NUMBER PRIMARY KEY, PERSONFIRSTNAME VARCHAR2(20), PERSONLASTNAME VARCHAR2(20) );
    CREATE TABLE T_PERSONADDRESS (PERSONID NUMBER NOT NULL, ADDRESSID NUMBER NOT NULL PRIMARY KEY );
    CREATE TABLE T_ADDRESS ( ADDRESSID NUMBER  PRIMARY KEY, ADDRESSTEXT VARCHAR2(200) );
    ALTER TABLE T_PERSONADDRESS ADD CONSTRAINT FK_PERSON_ADDR_PERSON_ID FOREIGN KEY (PERSONID) REFERENCES T_PERSON(PERSONID);
    ALTER TABLE T_PERSONADDRESS ADD CONSTRAINT FK_PERSON_ADDR_ADDR_ID FOREIGN KEY (ADDRESSID) REFERENCES T_ADDRESS(ADDRESSID);This is implementing a unidirectional one-to-many relationship between T_PERSON and T_ADDRESS according to the Hibernate and JPA recommendation. As far as I can see most schema designers would do this using by adding a column "PERSON_ID" (and associated FK) on the T_ADDRESS table and therefore not needing the T_PERSONADDRESS table.
    This being what it is, I would then like to create a cache-group as follows:
    CREATE READONLY CACHE GROUP "CACHEGROUPADDRESSES"
    AUTOREFRESH MODE INCREMENTAL INTERVAL 5 MINUTES
    STATE PAUSED
    FROM
      "SCHEMA1"."T_PERSON" (
        "PERSONID"        NUMBER            NOT NULL,
        "PERSONFIRSTNAME" VARCHAR2(20 BYTE),
        "PERSONLASTNAME"  VARCHAR2(20 BYTE),
        PRIMARY KEY("PERSONID")
      "SCHEMA1"."T_ADDRESS" (
        "ADDRESSID" NUMBER NOT NULL,
        "ADDRESSTEXT" VARCHAR2(20 BYTE),
        PRIMARY KEY("ADDRESSID")
      "SCHEMA1"."T_PERSONADDRESS" (
        "PERSONID"  NUMBER NOT NULL,
        "ADDRESSID" NUMBER NOT NULL,
        PRIMARY KEY("ADDRESSID"),
        FOREIGN KEY("PERSONID")
          REFERENCES "SCHEMA1"."T_PERSON"("PERSONID"),
        FOREIGN KEY("ADDRESSID")
          REFERENCES "SCHEMA1"."T_ADDRESS"("ADDRESSID")
      )This however gives me the error "TT8222: Multiple parent tables found" because TimesTen has failed to identify the one-to-many-using-link-table pattern.
    Without a schema re-write is there anything that I can do, alternatively will this be looked at for a future release of TimesTen?
    Edited by: TrisStev on Apr 16, 2012 10:37 AM

  • Getting One to Many Left Join to be in One Result Row...

    11G APEX 4.2
    At this time I don't have access to make a view or anything like that. Just select access to the data.
    BEGIN
    for i in (
    SELECT CAA.NODE_NAME THENODE,CNF.FEATURE_TYPE CNFFT from CMS.CMS_APP_ASSIGN "CAA"
    LEFT JOIN CMS.CMS_NODE_FEATURE "CNF" on CAA.NODE_NAME=CNF.NODE_NAME
    WHERE CAA.NODE_APP = :WHICHAPP and CAA.REMOVE_DT is NULL)
    LOOP
    dbms_output.put_line(i.THENODE||'--'||i.CNFFT||'<BR>');
    END LOOP;
    END;
    When this returns there is a row for each of the left joins.
    server1--CPUCount<BR>
    server1--ContactInfo<BR>
    server1--ContactInfo<BR>
    server1--ContactInfo<BR>
    server2--CPUCount<BR>
    What I would like to do it just have one row:
    NODENAME
    CPUCount
    Contactinfo
    Contact Info
    Contact Info
    ETC
    server1
    value1
    value2
    value4
    c
    Thanks

    Hi,
    Taking 1 column from N rows, and transforming that into N columns on 1 row is called Pivoting.
    The forum FAQ has a page on this subject.  See https://forums.oracle.com/message/9362005#9362005
    While you're in the Forum FAQ, also see https://forums.oracle.com/message/9362002

  • Left outer join using date range returns too many rows

    I am trying to pull data for a website.
    Names table:
    company_name varchar2(30)
    julian_day varchar2(3)
    logins number(3)
    login_errors number(3)
    Given a julian date range (e.g. 250-252), I am displaying the information from the Names table.
    The problem is that I also need to display changes (increases/decreases) in the data. I do that by coloring the text based on a 10% increase/decrease. Data for the 3 days 250-252 would be compared to data for the previous 3 days 247-249.
    Not all companies will report data on all days, so some gaps in the data may exist. Therefore, I cannot do just a simple join.
    I am trying to write a query that will give me this information if the user chooses days 250-252.
    Company_name
    sum(logins) for days 250-252
    sum(login_errors) for days 250-252
    sum(logins) for days 247-249
    sum(login_errors) for days 247-249
    The query I'm using is:
    select cur.company_name, sum(cur.logins),
    sum(cur.login_errors), sum(old.logins), sum(old.login_errors)
    FROM names cur LEFT OUTER JOIN names old
    ON cur.company_name = old.company_name
    WHERE cur.adate>='250' and cur.adate<='252'
    and old.adate>='247' and old.adate<='249'
    GROUP by cur.company_name
    Given this data:
    Company_name adate logins login_errors
    ABC 247 10 10
    ABC 248 20 20
    ABC 249 30 30
    ABC 250 15 15
    ABC 251 25 25
    ABC 252 35 35
    My problem is that it returns:
    adate cur.logins cur.login_err old.logins old.login_err
    250 15 15 60 60
    251 25 25 60 60
    252 35 35 60 60
    How can I get it to only give me the one "old" day's data? I went with the LEFT OUTER JOIN because it's possible that there is no data for an "old" day.
    Thanks in advance.....

    Your problem stems from the join itself, and would be the same even without the OUTER JOIN. With your data, there are 3 records in cur and 3 records in old. The join matches each record in cur to each record in old resulting in 9 records in total. Without the SUM, this is clear:
    SQL> SELECT cur.company_name, cur.logins, cur.login_errors,
      2         old.logins, old.login_errors, cur.adate cad, old.adate oad
      3  FROM names cur LEFT OUTER JOIN names old
      4                 ON cur.company_name = old.company_name
      5  WHERE cur.adate>=250 and cur.adate<=252 and
      6        old.adate>=247 and old.adate<=249;
    COMPANY_NA     LOGINS LOGIN_ERRORS     LOGINS LOGIN_ERRORS        CAD        OAD
    ABC                35           35         10           10        252        247
    ABC                25           25         10           10        251        247
    ABC                15           15         10           10        250        247
    ABC                35           35         20           20        252        248
    ABC                25           25         20           20        251        248
    ABC                15           15         20           20        250        248
    ABC                35           35         30           30        252        249
    ABC                25           25         30           30        251        249
    ABC                15           15         30           30        250        249
    9 rows selected.You can do this with only one reference to the table.
    SELECT company_name,
           SUM(CASE WHEN adate BETWEEN 250 and 252 THEN logins ELSE 0 END) curlog,
           SUM(CASE WHEN adate BETWEEN 250 and 252 THEN login_errors ELSE 0 END) curerr,
           SUM(CASE WHEN adate BETWEEN 247 and 249 THEN logins ELSE 0 END) oldlog,
           SUM(CASE WHEN adate BETWEEN 247 and 249 THEN login_errors ELSE 0 END) olderr
    FROM names
    WHERE adate BETWEEN 247 and 252
    GROUP BY company_nameHTH
    John

  • Help with outer joins in Oracle!!

    so far this is what i've come up with and the code below does not work. Can anyone please help me on how the sytanx of left joins and how to use multiple left joins in a single query in oracle?
    SELECT a.*, b.Position_CD, c.Skill_CD, d.Team_Name, d.Team_Country, d.Club, e.Structure_Name
    FROM Roster a, Roster_position b, roster_skill c, Team d, Team_Structure e
    where (a.Roster_ID = ((b.Roster_ID= c.Roster_Id(+)) b.roster_id(+)).......
    I dont' know how to add more left joins!
    Here is the query I'm trying to duplicate (which is a query from Ms Access databaase which works fine).
    SELECT a.*, b.Position_CD, c.Skill_CD, d.Team_Name, d.Team_Country, d.Club, e.Structure_Name
    from ((Roster a LEFT JOIN (Roster_Position b LEFT JOIN Roster_Skill c ON b.Roster_ID=c.Roster_ID) ON a.Roster_ID=b.Roster_ID) LEFT JOIN Team d ON a.Team_CD=d.Team_CD) LEFT JOIN Team_Structure e ON a.Team_Structure_CD=e.Team_Structure_CD
    ORDER BY a.Roster_Id;
    Any help or comments are greatly appreciated

    First,
    I am not one of the leading SQL brains here...but I'm taking a stab, nonetheless.
    Second,
    Here's my best guess - and it seems to me that it should work as there are not two outer joins between any two tables. I hope I decoded your joins correctly - quite a mess that Access syntax!
    SELECT a.*, b.position_cd, c.skill_cd, d.team_name, d.team_country, d.club, e.structure_name
    FROM ROSTER a, ROSTER_POSITION b, ROSTER_SKILL c, TEAM d, TEAM_STRUCTURE e
    WHERE a.roster_id = b.roster_id(+)
    AND b.roster_id = c.roster_id(+)
    AND a.team_cd = d.team_cd(+)
    AND a.team_structure = e.team_structure(+);Third,
    As an architect-dude, it seems to me that you have a serious
    modeling problem to need so many outer joins in such a basic
    grab of data. In any scale other than minute, the performance
    of this model will suffer dramatically. Specifically, why can't
    ROSTER have an equijoin with TEAM and with TEAM_STRUCTURE - as they
    appear to be lookup tables...
    Good Luck
    (I'm certain you'll get better SQL from the others),
    Michael O'Neill
    Publisher of the PigiWiki
    clever-idea.com

  • Best Practice - Outer Join between Fact and Dim table

    Hi Gurus,
    Need some advice on the below scenario
    I have an OOTB subject area and we have around 50-60 reports based on it. The related subject area Fact and Dim1 table are having inner join.
    Now I have a scenario for one report where outer join has to be implemented between Fact and Dim1. Here I am against changing the OOTB subject area join as the outer join will impact the performance of other 50-60 reports.
    Can anyone provide any inputs on what is the best way to handle this scenario?
    Thanks

    Ok. I tried this:
    Driving table : Fact, Left outer join -- didnt work.
    Driving table: Dimension D left outer join -- didnt work either
    In either the case, I see physical query as D left outer Join on Fact F. and omitting the rows.
    And then I tried this -
    Driving table: Fact, RIght outer join.
    Now, this is giving me error:
    Sybase][ODBC Driver]Internal Error. [nQSError: 16001] ODBC error state: 00000 code: 30128 message: [Sybase][ODBC Driver]Data overflow. Increase specified column size or buffer size. [nQSError: 16011] ODBC error occurred while executing SQLExtendedFetch to retrieve the results of a SQL statement. (HY000)
    I checked all columns, everything matched with database table type and size.
    I am pulling Fact.account number, Dimension.account name, Fact.Measures. I am seeing this error each time I pull Fact.Account number.

  • How can we make consecutive left outer joins in Composite Provider?

    Hi,
    For the following design:
    Sales order and Delivery DSO's are unions on field Delivery Number.
    Invoice(Billing DSO) is having left outer join and joins with Sales Order DSO's based on the field Sales Order Number.
    Shipment DSO has left outer join, joins with Invoice DSO based on Delivery number.
    My doubt here in this composite provider design, is more than one consecutive left outer joins(in Invoice, shipment dso join) are allowed?
    Since this is possible in SAP ERP through writing abap codes, I came across that this kind of modelling is not possible in BW on  Hana through Composite provide kindly suggest how can we achieve this design in SAP BW On hana.
    Regards,
    Antony Jerald.

    Hi,
    Could anyone please help me on this?
    Hope, you are able to understand my question.  Please suggest.
    Regards,
    Antony Jerald.

  • Workspace Manager 10.1.0.4 and Outer Joins

    We experience the following Problem:
    We have a schema containing several Tables, one of them includes a SDO_GEOMETRY column (some Tables are about 2 million rows in size). We have to use some outer - joins in our statements, unfortunately the database - model is a generic one.
    The outer joins seem to work fine when the schema is not version - enabled, the performance is ok. As soon as we version - enable the schema, the explain plans for the statements with outer joins radically change, there are several "full table access" - paths for large tables (including the one with the geometry column).
    Statistics are up to date (executed dbms_stats.gather_schema_stats() with cascade => true).
    Any Ideas?
    cheers,
    Nothi

    Hi Ben,
    Thanx for your fast answer!
    This is the Statement:
    SELECT ress_exemp.id as ress_exemp_id, ress_exemp.ress_klasse_id as
    ress_exemp_ress_klasse_id, ress_exemp.ress_standort_id as
    ress_exemp_ress_standort_id, ress_exemp.ortsnetz_id as
    ress_exemp_ortsnetz_id, ress_exemp.asb_id as ress_exemp_asb_id,
    ress_exemp.netzbezirk_id as ress_exemp_netzbezirk_id,
    TO_CHAR(ress_exemp.gueltig_von,'dd.mm.yyyy hh24:mi:ss') as
    ress_exemp_gueltig_von, TO_CHAR(ress_exemp.gueltig_bis,'dd.mm.yyyy
    hh24:mi:ss') as ress_exemp_gueltig_bis, ress_exemp.gf_aktion as
    ress_exemp_gf_aktion, ress_exemp.gdv as ress_exemp_gdv, ress_exemp.sp as
    ress_exemp_sp, ress_exemp.status as ress_exemp_status, ress_exemp.banr as
    ress_exemp_banr, ress_exemp.bezeichnung as ress_exemp_bezeichnung,
    ress_exemp.parent_id as ress_exemp_parent_id , GEHAEUSE.*, GEOMETRIE.*,
    NETZBEZIRK.*, LOKATION.ZEILE_1, ress_standort.id as rs_id,
    ress_standort.lokation_id as rs_lokation_id, ress_standort.geometrie_id as
    rs_geometrie_id, ress_standort.relative_position as rs_rel_position,
    ress_standort.verortung as rs_verortung, ress_standort.datenqu as
    rs_datenqu, ress_standort.name_datenqu as rs_name_datenqu ,
    cast(multiset(select * from RESS_EXEMP_GIS where ress_exemp_id=ress_exemp.id) as TYPE_RESS_EXEMP_GIS_LISTE) as Darstellung
    from ress_exemp, GEHAEUSE, RESS_STANDORT, GEOMETRIE, NETZBEZIRK, LOKATION
    WHERE ress_exemp.id = GEHAEUSE.id
    AND ress_exemp.netzbezirk_id=NETZBEZIRK.id(+)
    AND ress_exemp.ress_standort_id=ress_standort.id(+)
    AND ress_standort.geometrie_id = geometrie.id(+)
    AND ress_standort.lokation_id = lokation.id(+)
    AND ress_exemp.id in (select /*+ cardinality(nlist 10) */ * from TABLE(cast(:b_ids as TYPE_NUMBER_LISTE)) nlist)
    This is the plan (from trace) fro the above sql, not version enabled:
    Rows Row Source Operation
    1 NESTED LOOPS OUTER (cr=16 pr=5 pw=0 time=27663 us)
    1 NESTED LOOPS OUTER (cr=12 pr=2 pw=0 time=15850 us)
    1 NESTED LOOPS OUTER (cr=12 pr=2 pw=0 time=15828 us)
    1 NESTED LOOPS OUTER (cr=8 pr=1 pw=0 time=7964 us)
    1 NESTED LOOPS (cr=8 pr=1 pw=0 time=7945 us)
    1 NESTED LOOPS (cr=4 pr=0 pw=0 time=123 us)
    1 SORT UNIQUE (cr=0 pr=0 pw=0 time=67 us)
    1 COLLECTION ITERATOR PICKLER FETCH (cr=0 pr=0 pw=0 time=18 us)
    1 TABLE ACCESS BY INDEX ROWID RESS_EXEMP (cr=4 pr=0 pw=0 time=50 us)
    1 INDEX UNIQUE SCAN PK_RESS_EXEMP (cr=3 pr=0 pw=0 time=29 us)(object id 160705)
    1 TABLE ACCESS BY INDEX ROWID GEHAEUSE (cr=4 pr=1 pw=0 time=7811 us)
    1 INDEX UNIQUE SCAN PK_GEHAEUSE (cr=3 pr=0 pw=0 time=13 us)(object id 160765)
    0 TABLE ACCESS BY INDEX ROWID NETZBEZIRK (cr=0 pr=0 pw=0 time=10 us)
    0 INDEX UNIQUE SCAN PK_NETZBEZIRK (cr=0 pr=0 pw=0 time=5 us)(object id 160771)
    1 TABLE ACCESS BY INDEX ROWID RESS_STANDORT (cr=4 pr=1 pw=0 time=7848 us)
    1 INDEX UNIQUE SCAN PK_RESS_STANDORT (cr=3 pr=0 pw=0 time=14 us)(object id 160701)
    0 TABLE ACCESS BY INDEX ROWID GEOMETRIE (cr=0 pr=0 pw=0 time=9 us)
    0 INDEX UNIQUE SCAN PK_GEOMETRIE (cr=0 pr=0 pw=0 time=4 us)(object id 160694)
    1 TABLE ACCESS BY INDEX ROWID LOKATION (cr=4 pr=3 pw=0 time=11838 us)
    1 INDEX UNIQUE SCAN PK_LOKATION (cr=3 pr=2 pw=0 time=7320 us)(object id 160692)
    Takes about 0.05 seconds to execute.
    Plan (from trace) after version - enabling and gather_schema_stats:
    Rows Row Source Operation
    1 FILTER (cr=249798 pr=313734 pw=84427 time=192750716 us)
    1 HASH JOIN RIGHT SEMI (cr=249798 pr=313734 pw=84427 time=240955926 us)
    1 COLLECTION ITERATOR PICKLER FETCH (cr=0 pr=0 pw=0 time=21 us)
    688292 HASH JOIN RIGHT OUTER (cr=249798 pr=313734 pw=84427 time=285035131 us)
    21610 VIEW (cr=235 pr=0 pw=0 time=172975 us)
    21610 FILTER (cr=235 pr=0 pw=0 time=108142 us)
    21610 TABLE ACCESS FULL NETZBEZIRK_LT (cr=235 pr=0 pw=0 time=43305 us)
    0 FILTER (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN WM$NEXTVER_TABLE_NV_INDX (cr=0 pr=0 pw=0 time=0 us)(object id 9186)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$VERSION_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$VERSION_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8896)
    0 VIEW (cr=0 pr=0 pw=0 time=0 us)
    0 UNION-ALL (cr=0 pr=0 pw=0 time=0 us)
    0 FILTER (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN MODIFIED_TABLES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8917)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS BY INDEX ROWID WM$VERSION_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN WM$VERSION_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8896)
    0 INDEX UNIQUE SCAN MODIFIED_TABLES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8917)
    688292 HASH JOIN RIGHT OUTER (cr=249563 pr=313734 pw=84427 time=279469137 us)
    515484 VIEW (cr=19385 pr=0 pw=0 time=6701465 us)
    515484 FILTER (cr=5140 pr=0 pw=0 time=2577569 us)
    515506 TABLE ACCESS FULL GEOMETRIE_LT (cr=5102 pr=0 pw=0 time=1546659 us)
    0 FILTER (cr=3 pr=0 pw=0 time=115 us)
    1 INDEX RANGE SCAN WM$NEXTVER_TABLE_NV_INDX (cr=2 pr=0 pw=0 time=38 us)(object id 9186)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$VERSION_TABLE (cr=1 pr=0 pw=0 time=25 us)
    0 INDEX UNIQUE SCAN WM$VERSION_PK (cr=1 pr=0 pw=0 time=16 us)(object id 8896)
    1 VIEW (cr=35 pr=0 pw=0 time=958 us)
    1 UNION-ALL (cr=35 pr=0 pw=0 time=894 us)
    1 FILTER (cr=24 pr=0 pw=0 time=378 us)
    1 INDEX UNIQUE SCAN MODIFIED_TABLES_PK (cr=22 pr=0 pw=0 time=263 us)(object id 8917)
    2 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=4 pr=0 pw=0 time=62 us)
    2 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=2 pr=0 pw=0 time=24 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    2 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=4 pr=0 pw=0 time=62 us)
    2 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=2 pr=0 pw=0 time=24 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 NESTED LOOPS (cr=11 pr=0 pw=0 time=290 us)
    0 TABLE ACCESS BY INDEX ROWID WM$VERSION_TABLE (cr=11 pr=0 pw=0 time=225 us)
    0 INDEX RANGE SCAN WM$VERSION_PK (cr=11 pr=0 pw=0 time=151 us)(object id 8896)
    0 INDEX UNIQUE SCAN MODIFIED_TABLES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8917)
    672794 HASH JOIN OUTER (cr=230178 pr=295905 pw=67004 time=197075574 us)
    672794 HASH JOIN RIGHT OUTER (cr=40108 pr=77885 pw=38990 time=92436750 us)
    690002 VIEW (cr=6208 pr=6139 pw=0 time=5649517 us)
    690002 FILTER (cr=6208 pr=6139 pw=0 time=4269507 us)
    690021 TABLE ACCESS FULL RESS_STANDORT_LT (cr=6175 pr=6139 pw=0 time=2199551 us)
    0 FILTER (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN WM$NEXTVER_TABLE_NV_INDX (cr=0 pr=0 pw=0 time=0 us)(object id 9186)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$VERSION_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$VERSION_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8896)
    0 VIEW (cr=33 pr=0 pw=0 time=774 us)
    0 UNION-ALL (cr=33 pr=0 pw=0 time=719 us)
    0 FILTER (cr=22 pr=0 pw=0 time=268 us)
    0 INDEX UNIQUE SCAN MODIFIED_TABLES_PK (cr=20 pr=0 pw=0 time=144 us)(object id 8917)
    2 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=4 pr=0 pw=0 time=80 us)
    2 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=2 pr=0 pw=0 time=44 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    2 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=4 pr=0 pw=0 time=80 us)
    2 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=2 pr=0 pw=0 time=44 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 NESTED LOOPS (cr=11 pr=0 pw=0 time=236 us)
    0 TABLE ACCESS BY INDEX ROWID WM$VERSION_TABLE (cr=11 pr=0 pw=0 time=178 us)
    0 INDEX RANGE SCAN WM$VERSION_PK (cr=11 pr=0 pw=0 time=115 us)(object id 8896)
    0 INDEX UNIQUE SCAN MODIFIED_TABLES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8917)
    672794 HASH JOIN (cr=33900 pr=55205 pw=22449 time=60265506 us)
    672792 TABLE ACCESS FULL GEHAEUSE_LT (cr=7219 pr=7206 pw=0 time=10207784 us)
    2331315 TABLE ACCESS FULL RESS_EXEMP_LT (cr=26681 pr=25550 pw=0 time=35088531 us)
    6289491 VIEW (cr=190070 pr=190006 pw=0 time=94568502 us)
    6289491 FILTER (cr=190070 pr=190006 pw=0 time=81989512 us)
    6289491 TABLE ACCESS FULL LOKATION_LT (cr=190070 pr=190006 pw=0 time=63121025 us)
    0 FILTER (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN WM$NEXTVER_TABLE_NV_INDX (cr=0 pr=0 pw=0 time=0 us)(object id 9186)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$VERSION_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$VERSION_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8896)
    0 VIEW (cr=0 pr=0 pw=0 time=0 us)
    0 UNION-ALL (cr=0 pr=0 pw=0 time=0 us)
    0 FILTER (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN MODIFIED_TABLES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8917)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS BY INDEX ROWID WM$VERSION_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN WM$VERSION_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8896)
    0 INDEX UNIQUE SCAN MODIFIED_TABLES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8917)
    0 FILTER (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN WM$NEXTVER_TABLE_NV_INDX (cr=0 pr=0 pw=0 time=0 us)(object id 9186)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$VERSION_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$VERSION_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8896)
    0 VIEW (cr=0 pr=0 pw=0 time=0 us)
    0 UNION-ALL (cr=0 pr=0 pw=0 time=0 us)
    0 FILTER (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN MODIFIED_TABLES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8917)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS BY INDEX ROWID WM$VERSION_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN WM$VERSION_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8896)
    0 INDEX UNIQUE SCAN MODIFIED_TABLES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8917)
    0 FILTER (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN WM$NEXTVER_TABLE_NV_INDX (cr=0 pr=0 pw=0 time=0 us)(object id 9186)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$VERSION_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$VERSION_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8896)
    0 VIEW (cr=0 pr=0 pw=0 time=0 us)
    0 UNION-ALL (cr=0 pr=0 pw=0 time=0 us)
    0 FILTER (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN MODIFIED_TABLES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8917)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS BY INDEX ROWID WM$VERSION_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN WM$VERSION_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8896)
    0 INDEX UNIQUE SCAN MODIFIED_TABLES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8917)
    Rather long, sorry. As you can see, there are several TABLE ACCESS FULL - paths for large tables, causing a lot of user I/O.
    I also tried to use method_opt => 'FOR ALL COLUMNS SIZE 20', unfortunately it dindn't really change the plan.
    Have you got any ideas left?
    thank you for your help, anything can take me further
    regards,
    Nothi

  • Sorted one-to-many mapping

    Hi,
    I try to use a one-to-many relationship (join) with a sorted condition.
    I don't know how if I have to use transparent Indirection and how to customize my condition (ascending).
    regards

    That would be the name of the query key of the related class.
    Consider A (id, name, listOfBs) and B (id, name).
    To sort listOfBs based on the "name" attribute of B, I would use the argument "name" to the addAscending/addDescendingOrdering method.
    I hope this clarifies things for you,
    Christian

  • How to change the fetch size for a one-to-many relationship

    With Toplink 10.1.3, since using scrollablecursor is a prerequisites for changing the fetchsize on a query (using the setFetchSize), I am wondering if it would be possible to change the fetchsize of the query which is associated to a one-to-many relationship.
    So, is this possible? How ?

    In TopLink 10.1.3 you can set the fetch-size on any query, it has nothing to do with using a ScrollableCursor.
    Example:
    readQuery.setFetchSize(100);
    To set the fetch size on a mapping query use,
    mapping.getSelectionQuery().setFetchSize(100);
    In 10.1.3 you can only set this in code, not currently through XML or the Mapping Workbench. In 10.1.3.1 you should be able to set the value through XML as well.

  • Possibility of implementing "left outer join"

    Hi,
    I have four tables and the common fields in the tables are as given below
    Table         Field
    usr02        bname
    user_addr bname
    usr21        bname persnumber
    adr6                      persnumber
    Now I want to join these tables using "Left outer join", is there a possibility to join these tables,and also if anyone could give me the general idea of the select query,it would be helpful.
    P.S: I tried joining these tables using "inner join", but i got very few records.
           And also I tried joining the tables using "for all entries", but then I got redundant data, I did" sort itab, delete duplicate entries from itab", still i was not able to obtain the desired result from table adr6.So i want to implement a "left outer join".
    Edited by: Narayananchandran on Dec 31, 2010 2:20 PM

    Hi,
    Better to choose cross join instead of Left outer join.
    It will prevent the duplicates.
    So, try to use cross join.
    It will helps to you. check it once.

  • How just return one row of a one to many join..

    So I have a one to many join where the SMOPERATOR table has data I need however it has a couple of rows that match the JOIN condition in there. I just need to return one row. I think this can be accomplished with a subquery in the join however have not been able to come up with the right syntax to do so.
    So:
    SELECT "NUMBER" as danumber,
    NAME,
    SMINCREQ.ASSIGNMENT,
    SMOPERATOR.PRIMARY_ASSIGNMENT_GROUP,
    SMOPERATOR.WDMANAGERNAME,
    SMINCREQ.owner_manager_name,
    SMINCREQ.subcategory, TO_DATE('01-'||TO_CHAR(open_time,'MM-YYYY'),'DD-MM-YYYY')MONTHSORT,
    (CASE WHEN bc_request='f' THEN 'IAIO'
    WHEN (bc_request='t' and substr(assignment,1,3)<>'MTS') THEN 'RARO'
    WHEN (bc_request='t' and substr(assignment,1,3)='MTS') THEN 'M'
    ELSE 'U' end) as type
    from SMINCREQ
    left outer join SMOPERATOR on SMINCREQ.assignment=SMOPERATOR.primary_assignment_group
    WHERE SMINCREQ.owner_manager_name=:P170_SELECTION and SMOPERATOR.wdmanagername=:P170_SELECTION
    AND open_time BETWEEN to_date(:P170_SDATEB,'DD-MON-YYYY') AND to_date(:P170_EDATEB,'DD-MON-YYYY')
    AND
    (bc_request='f' and subcategory='ACTIVATION' and related_record<>'t')
    OR
    (bc_request='f' and subcategory<>'ACTIVATION')
    OR
    (bc_request='t' and substr(assignment,1,3)<>'MTS')
    order by OPEN_TIMe

    Hi,
    This sounds like a Top-N Query , where you pick N items (N=1 in this case) off the top of an orderded list. I think you want a separate ordered list for each assignment; the analytic ROW_NUMBER function does that easily.
    Since you didn't post CREATE TABLE and INSERT statements for your sample data, I'll use tables from the scott schema to show how this is done.
    Say you have a query like this:
    SELECT       d.dname
    ,       e.empno, e.ename, e.job, e.sal
    FROM       scott.dept  d
    JOIN       scott.emp   e  ON   d.deptno = e.deptno
    ORDER BY  dname
    ;which produces this output:
    DNAME               EMPNO ENAME      JOB              SAL
    ACCOUNTING           7934 MILLER     CLERK           1300
    ACCOUNTING           7839 KING       PRESIDENT       5000
    ACCOUNTING           7782 CLARK      MANAGER         2450
    RESEARCH             7876 ADAMS      CLERK           1100
    RESEARCH             7902 FORD       ANALYST         3000
    RESEARCH             7566 JONES      MANAGER         2975
    RESEARCH             7369 SMITH      CLERK            800
    RESEARCH             7788 SCOTT      ANALYST         3000
    SALES                7521 WARD       SALESMAN        1250
    SALES                7844 TURNER     SALESMAN        1500
    SALES                7499 ALLEN      SALESMAN        1600
    SALES                7900 JAMES      CLERK            950
    SALES                7698 BLAKE      MANAGER         2850
    SALES                7654 MARTIN     SALESMAN        1250Now say you want to change the query so that it only returns one row per department, like this:
    DNAME               EMPNO ENAME      JOB              SAL
    ACCOUNTING           7782 CLARK      MANAGER         2450
    RESEARCH             7876 ADAMS      CLERK           1100
    SALES                7499 ALLEN      SALESMAN        1600where the empno, ename, job and sal columns on each row of output are all taken from the same row of scott.emp, though it doesn't really matter which row that is.
    One way to do it is to use the analytic ROW_NUMBER function to assign a sequence of unique numbers (1, 2, 3, ...) to all the rows in each department. Since each sequence startw with 1, and the numbers are unique within a department, there will be exactly one row per departement that was assigned the numebr 1, and we''ll display that row.
    Here's how to code that:
    WITH     got_r_num     AS
         SELECT     d.dname
         ,     e.empno, e.ename, e.job, e.sal
         ,     ROW_NUMBER () OVER ( PARTITION BY  d.dname
                                   ORDER BY          e.ename
                           )         AS r_num
         FROM     scott.dept  d
         JOIN     scott.emp   e  ON   d.deptno = e.deptno
    SELECT       dname
    ,       empno, ename, job, sal
    FROM       got_r_num
    WHERE       r_num     = 1
    ORDER BY  dname
    ;Notice that he sub-query got_r_num is almost the same as the original query; only it has one additional column, r_num, in the SELECT clause, and the sub-qeury does not have an ORDER BY clause. (Sub-queries almost never have an ORDER BY clause.)
    The ROW_NUMBER function must have an ORDER BY clause. In this example, I used "ORDER BY ename", meaning that, within each department, the row with the first ename (in sort order) will get r_num=1. You can use any column, or expression, or expressions in the ORDER BY clause. You muight as well use something consistent and predictable, like ename, but if you really wanted arbitrary numbering you could use a constant in the analytic ORDER BY clause, e.g. "ORDER BY NULL".

  • Joining Tables Involving "one to many"

    I have a situation where a customer gets a basic "license" to perform a business then he or she may get multiple "permits" to perform sub tasks of the basic business plan.
    I must join the "license" table with the "permits" table. I have currently joined them with a license identification number that appears in both tables, without qualification as to "one to one" or "outer join".
    There is always a license ID number in the licensing table.
    There may be multiple occurrance's of the license ID number in the permits table.
    Should I qualify the join?

    Thank you for the rapid response. I am returning to the Discoverer product after a long absence and need brushing up on many standard concepts.
    In a recent response to a question on joins by another requestor, the forum respondent advised that "you didn't include the join in a condition i.e. master table item x is equal to detail table item x". Isn't it a redundancy to put the join in a condition if a joins already exists for the detail table information. I know that I can trick the CBO into more rapid response by including redundant conditions in the query such as a date range that includes all the records in a table. A test demonstrated that the inclusion of the join in the condition caused the data to literally explode on the screen.

  • Oracle OUTER JOIN on more than one table

    Hi!
    Friends, please help with this urgent problem: How can an outer join be written on more than one table?
    An SQL Server query:
    SELECT * from a INNER JOIN b on a.id = b.id LEFT OUTER JOIN c ON c.id = a.id AND c.id = b.id
    works fine with SQL SERVER
    But Oracle query:
    SELECT * from a,b,c WHERE a.id = b.id AND a.id = c.id (+) AND b.id = c.id (+)
    gives an error: OUTER JOIN cannot be used on more than one table? Why?
    I use OracleDriver from classes12.zip to connect to Oracle8i database.
    Please, help!

    The Oracle 8i and later SQL reference reads that the following "join_types" are supported and under this syntax it does not limit the LEFT OUTER JOIN (syntax the same as SQLServer example in original note) to two tables as implied in these notes:
    The join_type indicates the kind of join being performed:
    Specify INNER to indicate explicitly that an inner join is being performed. This is the default.
    Specify RIGHT to indicate a right outer join.
    Specify LEFT to indicate a left outer join.
    Specify FULL to indicate a full or two-sided outer join. In addition to the inner join, rows from both tables that have not been returned in the result of the inner join will be preserved and extended with nulls.
    You can specify the optional OUTER keyword following RIGHT, LEFT, or FULL to explicitly clarify that an outer join is being performed.

Maybe you are looking for