Generic connectivity to Sybase and outer join problem

I have a need to query records from a Sybase database running on Linux
(32-bit) and am using Oracle 10.2.0.3 with generic connectivity (no
specific heterogeneous service/transparent gateway for Sybase on Linux, that I see). We have installed
an ODBC driver on the Oracle server and can query the Sybase database
without difficulty except for outer joins.
I have tried using both the Oracle syntax and the ANSI syntax. Both
return results that are consistent with using an inner join. The ANSI
query, run directly against the Sybase database returns the correct
data (of course, removing the database link syntax).
I was looking into the possibility of using dbms_hs_passthrough, but
it does not appear to be part of the generic connectivity.
Is there a better/right way of doing this? Aren't outer joins supported?
Thanks,
Vince

As a followup, I did get dbms_hs_passthrough working and am able to get the correct data back. However, I would like to leave this as a backup.
Aren't outer joins supported in the generic connectivity?
Vince

Similar Messages

  • Difference between inner join and outer join

    1.Difference between inner join and outer join
    2.wht is the difference in using hide and get crusor value in interactive.
    3. Using join is better or views in writting program . Which is better.

    Table 1                      Table 2
    A
    B
    C
    D
    D
    E
    F
    G
    H
    a1
    b1
    c1
    1
    1
    e1
    f1
    g1
    h1
    a2
    b2
    c2
    1
    3
    e2
    f2
    g2
    h2
    a3
    b3
    c3
    2
    4
    e3
    f3
    g3
    h3
    a4
    b4
    c4
    3
    |--|||--|
        Inner Join
        |--||||||||--|
        | A  | B  | C  | D  | D  | E  | F  | G  | H  |
        |--||||||||--|
        | a1 | b1 | c1 | 1  | 1  | e1 | f1 | g1 | h1 |
        | a2 | b2 | c2 | 1  | 1  | e1 | f1 | g1 | h1 |
        | a4 | b4 | c4 | 3  | 3  | e2 | f2 | g2 | h2 |
        |--||||||||--|
    Example
    Output a list of all flights from Frankfurt to New York between September 10th and 20th, 2001 that are not sold out:
    DATA: DATE   LIKE SFLIGHT-FLDATE,
          CARRID LIKE SFLIGHT-CARRID,
          CONNID LIKE SFLIGHT-CONNID.
    SELECT FCARRID FCONNID F~FLDATE
        INTO (CARRID, CONNID, DATE)
        FROM SFLIGHT AS F INNER JOIN SPFLI AS P
               ON FCARRID = PCARRID AND
                  FCONNID = PCONNID
        WHERE P~CITYFROM = 'FRANKFURT'
          AND P~CITYTO   = 'NEW YORK'
          AND F~FLDATE BETWEEN '20010910' AND '20010920'
          AND FSEATSOCC < FSEATSMAX.
      WRITE: / DATE, CARRID, CONNID.
    ENDSELECT.
    If there are columns with the same name in both tables, you must distinguish between them by prefixing the field descriptor with the table name or a table alias.
    Note
    In order to determine the result of a SELECT command where the FROM clause contains a join, the database system first creates a temporary table containing the lines that meet the ON condition. The WHERE condition is then applied to the temporary table. It does not matter in an inner join whether the condition is in the ON or WHEREclause. The following example returns the same solution as the previous one.
    Example
    Output of a list of all flights from Frankfurt to New York between September 10th and 20th, 2001 that are not sold out:
    DATA: DATE   LIKE SFLIGHT-FLDATE,
          CARRID LIKE SFLIGHT-CARRID,
          CONNID LIKE SFLIGHT-CONNID.
    SELECT FCARRID FCONNID F~FLDATE
        INTO (CARRID, CONNID, DATE)
        FROM SFLIGHT AS F INNER JOIN SPFLI AS P
               ON FCARRID = PCARRID
        WHERE FCONNID = PCONNID
          AND P~CITYFROM = 'FRANKFURT'
          AND P~CITYTO   = 'NEW YORK'
          AND F~FLDATE BETWEEN '20010910' AND '20010920'
          AND FSEATSOCC < FSEATSMAX.
      WRITE: / DATE, CARRID, CONNID.
    ENDSELECT.
    Note
    Since not all of the database systems supported by SAP use the standard syntax for ON conditions, the syntax has been restricted. It only allows those joins that produce the same results on all of the supported database systems:
    Only a table or view may appear to the right of the JOIN operator, not another join expression.
    Only AND is possible in the ON condition as a logical operator.
    Each comparison in the ON condition must contain a field from the right-hand table.
    If an outer join occurs in the FROM clause, all the ON conditions must contain at least one "real" JOIN condition (a condition that contains a field from tabref1 amd a field from tabref2.
    Note
    In some cases, '*' may be specified in the SELECT clause, and an internal table or work area is entered into the INTO clause (instead of a list of fields). If so, the fields are written to the target area from left to right in the order in which the tables appear in the FROM clause, according to the structure of each table work area. There can then be gaps between table work areas if you use an Alignment Request. For this reason, you should define the target work area with reference to the types of the database tables, not simply by counting the total number of fields. For an example, see below:
    Variant 3
    ... FROM tabref1 LEFT [OUTER] JOIN tabref2 ON cond
    Effect
    Selects the data from the transparent database tables and/or views specified in tabref1 and tabref2. tabref1 und tabref2 both have either the same form as in variant 1 or are themselves join expressions. The keyword OUTER can be omitted. The database tables or views specified in tabref1 and tabref2 must be recognized by the ABAP-Dictionary.
    In order to determine the result of a SELECT command where the FROM clause contains a left outer join, the database system creates a temporary table containing the lines that meet the ON condition. The remaining fields from the left-hand table (tabref1) are then added to this table, and their corresponding fields from the right-hand table are filled with ZERO values. The system then applies the WHERE condition to the table.
    Left outer join between table 1 and table 2 where column D in both tables set the join condition:
    Table 1                      Table 2
    A
    B
    C
    D
    D
    E
    F
    G
    H
    a1
    b1
    c1
    1
    1
    e1
    f1
    g1
    h1
    a2
    b2
    c2
    1
    3
    e2
    f2
    g2
    h2
    a3
    b3
    c3
    2
    4
    e3
    f3
    g3
    h3
    a4
    b4
    c4
    3
    |--|||--|
        Left Outer Join
        |--||||||||--|
        | A  | B  | C  | D  | D  | E  | F  | G  | H  |
        |--||||||||--|
        | a1 | b1 | c1 | 1  | 1  | e1 | f1 | g1 | h1 |
        | a2 | b2 | c2 | 1  | 1  | e1 | f1 | g1 | h1 |
        | a3 | b3 | c3 | 2  |NULL|NULL|NULL|NULL|NULL|
        | a4 | b4 | c4 | 3  | 3  | e2 | f2 | g2 | h2 |
        |--||||||||--|
    Regards
    Prabhu

  • Snow Base Station Connection Flashes In and Out

    I just got a 'new' snow base station, and once I set it up, its connection cycles in and out and in and out. AP Grapher shows spikes in noise, signal, quality, everything. Connection last less than a second, drops for maybe a full second, connects again for less than a second, ad nauseam. The old, graphite one, is fine. I checked to make sure the new one is on the same channel, same multicast rate, same interference robustness, etc. Everything is the same except that the snow base station has a 128 bit password. What's going on with this thing?

    Woops. Should have gone through all the settings. In case it helps anyone else - resetting and resetting-up does not remove Access Control Settings. My computers weren't on the authorized list.

  • Connections to Sybase and DB2

    Hi,
    Does SQLDevelopeer can connect to Sybase and DB2 databases, do I have to pay something else?
    Regards,

    hi,
    SQLDevelopeer can connect to Sybase and DB2 databases besides other databases. You need to include JDBC driver jar files in SQLDev preference settings. Please check help doc for more information.
    - Rakesh

  • Inner join and outer join

    hi friends,
    how to use inner join and outer join methods in abap. pls explain

    you have to code them
    Seriously, I suggest you take an ABAP class, it's out of the scope of this forum to tech you how to program joins.
    Markus

  • Inner join and outer  join in infosets

    hi everyone,
    i have a doubt in infosets...
    when and why we use inner and outer joins(right outer join and left outer join) for infoset
    please give a real time scenario........
    Thanks in advance.
    Bye.

    Hello,
    Inner join:
    For example, the requirement is to show all sales documents where you have delivery exists. In this case, you join both sales ods and delivery ods in a infoset as inner join. This will match the record against the reference documents and pull only matched records.  
    Outer Join:
    Suppose you want to pull all billing/invoice details along with their FI documents related data in a report. Assume that always there might be a situation that invoice exists but not posted to FI, however, you want to have all billing documents details either it has FI document or not. In this case, you link both Billing data and FI document data in a outer join.  This will pull all invoices data either FI document exists or not.   Other words, you want to show one side of data always but adding additional details from differenent source if data exists.
    Hope, it clarifies your doubt. Let me know if any questions.
    Thanks
    Viswa

  • Performance Tunning - Connect By and Outer Join Used - Urgent

    Hi,
    I have written a query with the outer join and connect by prior since to establish the parent child relation ship.
    All the tables having 2 lakhs record but the final result set is 20 thousand rows.
    The query is taking 5 minutes to complete the execution. How could i improve the performance.
    The query is
    SELECT
    'ABC' hrchy_id,
    SUBSTR(c.abc_cd,1,1) ,
    a.org_no bu_node_id,
    SUBSTR(d.abc_cd,1,1) ,
    a.prnt_org ,
    level hrchy_lvl_nb,
    a.eff_from_dt,
    a.eff_to_dt,
    FROM ((parent a INNER JOIN f_org b ON (a.org_no = b.org_no))
         left join org c on ( (a.org_no = (c.abc_cd)))
    ) left join org d on ( (a.prnt_org = d.abc_cd)))
    WHERE a.co_cd ='000'
    START with a.prnt_org = '0'
    CONNECT BY a.prnt_org = PRIOR a.org_no
    ORDER SIBLINGS BY a.org_no;
    Please suggest any idea or commands to improve the performance.
    Thanks in advance.

    Can you provide the structure of tree based SQL.
    Thanks in advance.But you have it already :-)
    SELECT
    'ABC' hrchy_id,
    a.org_no bu_node_id,
    a.prnt_org ,
    level hrchy_lvl_nb,
    a.eff_from_dt,
    a.eff_to_dt,
    FROM parent a WHERE a.co_cd ='000'
    START with a.prnt_org = '0'
    CONNECT BY a.prnt_org = PRIOR a.org_no
    ORDER SIBLINGS BY a.org_no;Regards
    Dmytro

  • Left outer join problem -- need feedback

    using crystal 2008
    haveing prolbems with a left outerjoin to get a blank field(null) to show up.
    basically i have some po line have have long descriptions or text fields that i want to include with the report. Below is my sql statement. I have written a formula with a join between 2 fields to get the report to work- this does but- it leave the polines off that do not have a long description.  I have tried left outer joins but seem to be having problems.  The long description field where the data is actually at is under my po.line table, although serveral area have long description fields -
    *one note i had to add a duplicate table to the field to get some items in my header to work properly - not sure if this is effecting the report or not.
    OK- when I set up the link to a LO join enforce from = to
    and dont add the ldtext.field to the report the left outjoin works(but no long description)and all my line items show up.
    1. when I keep the same join and add either just the ld.text field to  the report it comes back with a error saying invalid table
    2. when i use my formula that joins the ld.text and po.line and place it in the report with the same left outerjoin i get the same failure.
    3.  when i dont reference the ldtext(field) at all in the report it works fine w/ the lo join
    4. when i Dont use a left outer join and use my formula(see below)
    if not isnull(({LONGDESCRIPTION.LDTEXT }))
    then {POLINE.DESCRIPTION}+{LONGDESCRIPTION.LDTEXT}
    else {POLINE.DESCRIPTION}
    and link from poline.ld
    to ld.ldtext - my formula works and populates the po.line and the ld.text together - except that any po.line with no description will not show up. Like its not there.
    Not sure what to do?
    here is my current sql statement with the longdescription field in the select statement
    here is the error statement i am getting:
    Failed to retrieve data from the database:
    Details:42000[intersolv][odb sql base driver][sql base] 00906 itn invalid table name[database vendor code:906]
    sql statement:
    SELECT "PO"."PONUM", "PO"."STATUS", "PO"."VENDOR",
    "COMPANIES"."NAME", "COMPANIES"."ADDRESS1",
    "COMPANIES"."ADDRESS2", "COMPANIES"."ADDRESS3",
    "COMPANIES"."ADDRESS4", "COMPANIES"."PHONE",
    "COMPANIES"."FAX", "COMPANIES_1"."NAME",
    "COMPANIES_1"."ADDRESS1", "COMPANIES_1"."ADDRESS2",
    "COMPANIES_1"."ADDRESS3", "COMPANIES_1"."ADDRESS4",
    "COMPANIES_1"."CONTACT", "COMPANIES_1"."PHONE",
    "COMPANIES_1"."FAX", "PO"."PURCHASEAGENT",
    "PO"."ORDERDATE",
    "PO"."REQUIREDDATE", "PO"."PAYMENTTERMS",
    "PO"."SHIPVIA", "PO"."FREIGHTTERMS", "PO"."FOB",
    "POLINE"."DESCRIPTION", "POLINE"."ITEMNUM",
    "POLINE"."ORDERQTY", "POLINE"."UNITCOST",
    "POLINE"."LOADEDCOST", "POLINE"."POLINENUM",
    "PO"."SHIPTOATTN", "LONGDESCRIPTION"."LDTEXT"
    FROM   ("MAXIMO"."PO" "PO" LEFT OUTER JOIN
    "MAXIMO"."LONGDESCRIPTION" "LONGDESCRIPTION" ON "PO"."LDKEY"="LONGDESCRIPTION"."LDKEY"),
    "MAXIMO"."POLINE" "POLINE",
    "MAXIMO"."COMPANIES" "COMPANIES_1",
    "MAXIMO"."COMPANIES" "COMPANIES"
    WHERE  ("PO"."PONUM"="POLINE"."PONUM") AND ("PO"."VENDOR"="COMPANIES_1"."COMPANY") AND ("PO"."SHIPTO"="COMPANIES"."COMPANY") AND "PO"."PONUM"='3386-053'

    If you took the time to read this thanks.... turns out... and I just want to pull my hair out over this.  My connection had a  old odbc driver so somehow it would not allow a left outer join....go figure - weeks of agony over that..... thanks ....have to say love this forum.

  • 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

  • Correlated sub-query/outer join problem

    Hi,
    I have a problem similar to this one (Outer join with correlated subquery but I'm struggling to find a solution for mine!
    The following query works OK unless there is no entry in room_prices, so I need to outer join somehow to that table otherwise it doesn't return any rows.
    The main difference between the query in the other thread and mine is that mine has an extra table (bookings b) in the sub-query, which is complicating things a bit.
    select b.book_from,
         b.book_to,
         b.flat_rate,
         nvl(c.discount,0),
         p.hourly,
         p.half_day,
         p.daily,
         p.discountable,
         p.surcharge,
         l.evening_start,
         nvl(b.full_day,'N')
    from booking.bookings b,
    booking.customer c,
    booking.room_prices p,
    booking.rooms r,
    booking.location l
    where b.id = 9272
    and c.id = b.customer
    and b.room = p.room
    and b.room = r.id
    and r.loc = l.id
    and p.from_date =
    select max(p2.from_date)
    from booking.room_prices p2
    where p2.room = p.room
    and p2.from_date < b.book_from
    Could anyone suggest a way to re-write the query so that it is outer joined to room_prices?
    Thanks,
    Hazel

    Thanks for both of your responses.
    Unfortunately your suggestion didn't work Dmytro - still no rows are returned.
    Here are some table creation scripts and test data to insert:
    CREATE TABLE BOOKINGS
    ID NUMBER NOT NULL,
    ROOM NUMBER NOT NULL,
    CUSTOMER NUMBER NOT NULL,
    BOOK_FROM DATE NOT NULL,
    BOOK_TO DATE NOT NULL,
    CONFIG VARCHAR2(24) NOT NULL,
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    DELEGATES NUMBER,
    NARRATIVE VARCHAR2(256),
    CONTACT_DETAILS VARCHAR2(400),
    CONFIRMED VARCHAR2(1),
    CANC_REASON NUMBER,
    FULL_DAY VARCHAR2(1),
    FLAT_RATE NUMBER,
    STANDBY NUMBER,
    TOTAL_STANDBY_TIME DATE,
    PRE_STANDBY_TIME DATE,
    PRE_STANDBY NUMBER,
    GL_CODE VARCHAR2(20)
    CREATE TABLE CUSTOMER
    ID NUMBER NOT NULL,
    CUSTOMER VARCHAR2(160) NOT NULL,
    CONTACT_ADDRESS VARCHAR2(240),
    CONTACT_TELEPHONE VARCHAR2(20),
    CONTACT_EMAIL VARCHAR2(160),
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    DISCOUNT NUMBER(5,2),
    CUST_TYPE VARCHAR2(1),
    CONTACT_FAX VARCHAR2(20),
    DEBTOR_NO VARCHAR2(20),
    BC_CONTACT VARCHAR2(64)
    CREATE TABLE ROOMS
    ID NUMBER NOT NULL,
    LOC NUMBER NOT NULL,
    NAME VARCHAR2(160) NOT NULL,
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    ACTIVE VARCHAR2(1),
    ROOM_DESC VARCHAR2(2000)
    CREATE TABLE LOCATION
    ID NUMBER NOT NULL,
    NAME VARCHAR2(240) NOT NULL,
    ADDRESS VARCHAR2(240),
    PCODE VARCHAR2(8),
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    CONF_RDF VARCHAR2(10),
    CLOSING VARCHAR2(5),
    EVENING_START VARCHAR2(5)
    CREATE TABLE ROOM_PRICES
    ROOM NUMBER NOT NULL,
    FROM_DATE DATE NOT NULL,
    HOURLY NUMBER(6,2),
    HALF_DAY NUMBER(6,2),
    DAILY NUMBER(6,2),
    DISCOUNTABLE VARCHAR2(1),
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    SURCHARGE NUMBER(6,2)
    Insert into bookings
    (ID, ROOM, CUSTOMER, BOOK_FROM, BOOK_TO, CONFIG, CREATED_DATE, CREATED_BY, UPDATED_DATE, UPDATED_BY, DELEGATES, NARRATIVE, CONTACT_DETAILS, CONFIRMED, FLAT_RATE, PRE_STANDBY_TIME, PRE_STANDBY)
    Values
    (9272, 7466, 4946, TO_DATE('10/25/2005 10:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/25/2005 13:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'Default', TO_DATE('10/27/2005 15:35:02', 'MM/DD/YYYY HH24:MI:SS'), 'HSIS0201', TO_DATE('10/27/2005 15:36:26', 'MM/DD/YYYY HH24:MI:SS'), 'HSIS0201', 1, 'another meeting', 'Hazel', 'Y', 40, TO_DATE('10/25/2005 09:30:00', 'MM/DD/YYYY HH24:MI:SS'), 1800);
    Insert into customer
    (ID, CUSTOMER, CONTACT_ADDRESS, CONTACT_TELEPHONE, CREATED_DATE, CREATED_BY, CUST_TYPE, BC_CONTACT)
    Values
    (4946, 'Association of Teachers', 'Address', '0191 8887777', TO_DATE('09/22/2003 08:05:47', 'MM/DD/YYYY HH24:MI:SS'), 'Dataload', 'B', 'Miss Jones');
    Insert into rooms
    (ID, LOC, NAME, CREATED_DATE, CREATED_BY, UPDATED_DATE, UPDATED_BY, ACTIVE)
    Values
    (7466, 308, ' Counselling Room 1', TO_DATE('04/11/2005 10:55:33', 'MM/DD/YYYY HH24:MI:SS'), 'BJAC1906', TO_DATE('06/22/2005 14:43:50', 'MM/DD/YYYY HH24:MI:SS'), 'HSIS0201', 'Y');
    Insert into location
    (ID, NAME, ADDRESS, PCODE, CREATED_DATE, CREATED_BY, UPDATED_DATE, UPDATED_BY, CONF_RDF, CLOSING, EVENING_START)
    Values
    (308, 'Business Centre', 'Address', 'NE30 1NT', TO_DATE('03/19/2003 13:07:35', 'MM/DD/YYYY HH24:MI:SS'), 'BJAC1906', TO_DATE('06/09/2005 11:17:09', 'MM/DD/YYYY HH24:MI:SS'), 'BJAC1906', 'BKCF_2', '22:30', '18:00');
    Thanks,
    Hazel

  • Outer join problem (ORA-01799)

    We have a database design roughly as follows:
    - A STAFF table (columns don't matter here).
    - Resources have a cost per hour that varies over time, so we have a STAFF_COST table with an effective date and a cost per hour
    - A PROJECT table (columns don't matter here).
    - Projects can have staff assigned, so we have a PROJECT_STAFF table which has foreign keys to the PROJECT and STAFF table.
    - Project staff have a cost per hour, which can vary over time, and be different to the (default) staff costs. So we have a PROJECT_STAFF_COST table which uses the PROJECT_STAFF foreign key, with an effective date and a cost per hour
    - Staff work on tasks so we have a TIMESHEET_TASK and TIMESHEET_DAY tables which define a project worked on, task within the project (optional as time can be 'entered against the project', who is recording the time, the hours worked and the day the hours were worked.
    So when timesheet information is entered we have three scenario's that we need to cover.
    1) The resource is a member of the project and the hours were worked on a day for which we have a project staff cost. That is, the project staff cost table has one or more rows for the staff member assigned to the given project with an effective date before the date the hours were entered against.
    2) The resource is a member of the project but the hours were worked on a day for which we do not have a project staff cost. That is, the project staff cost table has one or more entries for the staff member assigned to the given project, but all the effective dates are after the date the hours were entered against.
    3) The resource is not a member of the project. That is, the project staff cost table does not have any rows for the staff member. Time was entered 'against the project'.
    We need to work out the actual cost of the project. So we need to retrieve every day's timesheet entry, returning the hours assigned and the cost per hour relevant for that day. I have the following query:
    select tsh.staff_id, s.full_name, tsd.entry_date, tsd.hours as ProjectHours,
    psCOST_INFO.cost_per_hour as ProjectCost
    from timesheet_day tsd
    inner join timesheet_task tst on tst.timesheet_task_id = tsd.timesheet_task_id
    inner join timesheet_header tsh on tst.timesheet_header_id = tsh.timesheet_header_id
    inner join staff s on s.staff_id = tsh.staff_id
    left join (Select ps.project_id, ps.staff_id, psc.project_staff_id, psc.effective_date, psc.cost_per_hour
    from project_staff ps
    inner join project_staff_cost psc on ps.project_staff_id = psc.project_staff_id) as psCOST_INFO
    on psCOST_INFO.staff_id = tsh.staff_id and psCOST_INFO.project_id = tst.project_id
    and psCOST_INFO.effective_date = (select max(ps2.effective_date) from project_staff_cost ps2
    where ps2.project_staff_id = psCOST_INFO.project_staff_id
    and ps2.effective_date <= tsd.entry_date)
    where tst.project_id = 55825
    Using the left join covers scenario's 2 and 3 above because I will get null in the cost columns and can then take appropriate action. If I were to use an inner join, then hours in timesheets from scenario's 2 and 3 would be excluded, which is not what we want.
    The subselect using the MAX aggregate function is required to get the cost per hour most relevant for the timesheet day. That is, if there are several effective dates for the project staff member before the date in question, we want the most recent one. We can't just use the MAX one, however in case there is an effective date after the particular timesheet date. Sheesh...
    This query works fine in SQL Server. It it not allowed in Oracle and returns an ORA-01799 column may not be outer joined to a subquery.
    I'm not going to bother to ask why not. I just need a way to do what I want. I've spent days trying to move the code around but I either end up with an inner join (which returns fewer rows than I want) or it just plain don't work.
    Can someone help me rework this query to achieve the result I want?
    Thanks, Andrew

    Thanks for your reply, Laurent. In my experience trying to cut important corners in explaining a problem only serves to make it more difficult to solve. That pretty much was the smallest reproducable query that demonstrates the complexity of the problem I have. I'm not just trying to get which publishers live in the 'CA' state here...
    From what I have just read about rank() it serves the same purpose as max() on a given column, and getting the maximum or top ranked one just doesn't cut it. As I said in my original post that provided all the relevant (and no spurious) information on the problem, it is possible that there are effective dates AFTER the date we are interested in and they have to be excluded.
    I have to get the project staff cost row with the latest date that is before the timesheet date. That means I have to reference data in the outer query. Oracle seems to have a problem with that when used in an outer join.
    We are currently going down the track of 3 UNION'd statement to cover the 3 scenario's. A single query would be more efficient so if anyone can provide guidance I would appreciate it.
    Thanks, Andrew

  • Query Outer Join Problem

    I need to join these two tables and have a problem becuase it's difficult to join the tables with the keys.
    Basically here is a sample of the data.
    The only way I get the correct number of rows returned is with a left outer join on unit, asset_id and sequence_number.
    COST
    unit asset_id sequence_number
    01 113317 0
    01 113317 1
    01 113317 1
    ACQ_DETAIL
    unit asset_idnbsp sequence_number vendor_id
    01 113317 1 ABCConstruction
    So with the left outer join you'd get
    unit asset_idnbsp sequence_number vendor_id
    01 113317 0
    01 113317 1 ABCConstruction
    01 113317 1 ABCConstruction
    I need to join on sequence_number or else I get too many rows returned. Is there anyway I can keep the outer join (still joining on thows three keys) and have this returned.
    unit asset_idnbsp sequence_number vendor_id
    01 113317 0 ABCConstruction
    01 113317 1 ABCConstruction
    01 113317 1 ABCConstruction
    Thanks all!!

    COST
    unit         asset_id           seq_no   
    [pre]01            1137                   0        
    [pre]01            1137                   1        
    [pre]01            1137                   1       
    ACQ_DET
    [pre]unit         asset_id           seq_no      vendor_id  
    [pre]01            1137                   1              ABC      
    [pre]01            1137                   3              XYZ       
    RETURNS
    [pre]01            1137                   ABC           
    [pre]01            1137                   ABC           
    [pre]01            1137                   ABC           
    THANKS!!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Left Outer Join Problem for Multiple Condition

    Hi This is the code and I want to return the vlaues evens if it is not ther so my Sysntax is not right for that can you plz help me
    SELECT ap.descripcion AS Production_Description,
    conceptes.descripcion AS Concepts_Description ,
    um.Nomenclatura AS Unit_Measure ,
    -- real_daily_detail.FechaProduccion AS Production_Date ,
    period.Codigo as June,
    period.anio AS YEAR_08 ,
    rmd.Valor AS Values_Monthly,
    budgetd.Valor as Budget
    FROM sgr_area_produccion ap ,
    sgr_conceptos conceptes ,
    SGR_Unidad_Medida um ,
    SGR_Unidad_Produccion up ,
    SGR_Unidad_Area_Produccion uap ,
    SGR_Real_Mensual_Detalle rmd ,
    SGR_Periodo period ,
    SGR_Real_Mensual rm ,
    SGR_Presupuesto budget ,
    SGR_Presupuesto_Detalle budgetd
    where uap.ID_Unidad_Produccion = up.ID_Unidad_Produccion (+)
    and uap.ID_Area_Produccion = ap.ID_Area_Produccion (+)
    and rm.ID_Area_Produccion = uap.ID_Area_Produccion (+)
    and rm.ID_Unidad_Produccion = uap.ID_Unidad_Produccion (+)
    and rmd.ID_Unidad_Produccion = rm.ID_Unidad_Produccion (+)
    and rmd.ID_Area_Produccion = rm.ID_Area_Produccion (+)
    and rmd.ID_Periodo = rm.ID_Periodo (+)
    and period.ID_Periodo = rm.ID_Periodo (+)
    and conceptes.ID_Concepto = rmd.ID_Concepto (+)
    and budget.ID_Unidad_Produccion = uap.ID_Unidad_Produccion(+)
    and budget.ID_Area_Produccion = uap.ID_Area_Produccion (+)
    and budget.ID_Unidad_Produccion = budgetd.ID_Unidad_Produccion
    and budget.ID_Area_Produccion = budgetd.ID_Area_Produccion (+)
    and budget.ID_Periodo = budgetd.ID_Periodo (+)
    and period.ID_Periodo = budget.ID_Periodo (+)
    and period.Codigo = 'JUNIO-08'
    and conceptes.ID_Concepto = budgetd.ID_Concepto (+)
    and daily.ID_Area_Produccion = uap.ID_Area_Produccion (+)
    and daily.ID_Unidad_Produccion = uap.ID_Unidad_Produccion (+)
    and dailyd.ID_Unidad_Produccion = daily.ID_Unidad_Produccion(+)
    and dailyd.ID_Area_Produccion = daily.ID_Area_Produccion (+)
    and period.ID_Periodo = daily.ID_Periodo (+)
    and conceptes.ID_Concepto = dailyd.ID_Concepto (+)
    and um.ID_Unidad_Medida = conceptes .ID_Unidad_Medida (+)

    Oracle old outer join syntax had more restrictions than more recent ANSI outer join syntax. I do'nt want to emulate compiler and go through your code to spot any possible problems, even more if you cannot say also the exact error or exact problem what you get.
    And bear in mind that for outer joins THERE IS DIFFERENCE [url http://www.gplivna.eu/papers/sql_join_types.htm#p6.4]between join conditions and predicates in where clause.
    Gints Plivna
    http://www.gplivna.eu

  • Mixed Inner and Outer Joins in One SQL

    Oracle 11g.
    There are four tables:
    T1 (primary key: pk_t1)
    T2 (primary key: pk_t2, foreign key fk_t2_ref_t1)
    T3 (primary key: pk_t3, foreign key fk_t3_ref_t2)
    T4 (primary key: pk_t4, foreign key fk_t4_ref_t3)
    This is what I want to do:  inner join among T1, T2, and T3, then outer join with T4 (T4 may contain the null rows).  Something like:
    procedure sp_test(
    p_where_clause)
    select *
    from
         T1 inner joint T2 on pk_t1 = fk_t2_ref_t1
        inner joint T3 on pk_t2 = fk_t3_ref_t2
        left outer join T3 on pk_t3 = fk_t4_ref_t3
    where  p_where_clause;
    OR
    select *
    from
         T4 right outer join T3 on pk_t3 = fk_t4_ref_t3
        inner joint T2 on pk_t2 = fk_t3_ref_t2
        inner joint T1 on pk_t1 = fk_t2_ref_t1
    where  p_where_clause;
    Please help me to write a correct SQL to achieve this goal.
    Thanks

    Hi,
    Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved, so that the people who want to help you can re-create the problem and test their ideas.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    Always say which version of Oracle you're using (for example, 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002
    I'm guessing that your first attempt
    select *
    from
         T1 inner joint T2 on pk_t1 = fk_t2_ref_t1
        inner joint T3 on pk_t2 = fk_t3_ref_t2
        left outer join T3 on pk_t3 = fk_t4_ref_t3
    where  p_where_clause;
    was close; only you want to include t4 rather than a second copy of t3, and you need to spell JOIN correctly:
    SELECT  *        -- You'll probably want to specify columns
    FROM             t1
    INNER JOIN       t2     ON  pk_t1 = fk_t2_ref_t1
    INNER JOIN       t3     ON  pk_t2 = fk_t3_ref_t2
    LEFT OUTER JOIN  t4     ON  pk_t3 = fk_t4_ref_t3
    WHERE  ...

  • Query by example and outer join supported?

    Does TopLink support outer joins when using query by example and cursored streams? I am having problems getting this to work. It seems to completely ignore the requested outer join.
    I have tried several variations of what is below, but have never seen TopLink generate the outer join. This is against Oracle 9i on TopLink 9.0.4.5.
    Customer 1->1 Address (using valueholder indirection)
    ReadAllQuery q = new ReadAllQuery();
    q.setReferenceClass(Customer.class);
    QueryByExamplePolicy policy = new QueryByExamplePolicy();
    policy.addSpecialOperation(String.class, "like");
    q.setQueryByExamplePolicy(policy);
    ExpressionBuilder builder = q.getExpressionBuilder();
    Expression addressExp = builder.getAllowingNull("address");
    q.addJoinedAttribute(addressExp);
    q.addOrdering(addressExp.get("city").ascending());
    q.useCursoredStream(end-start, end-start);
    q.setExampleObject(exampleCustomer);
    CursoredStream stream = (CursoredStream)s.executeQuery(q);
    ...iterate through the stream...
    Note, that the database level relationship is expressed through a target foreign key.
    (     addressMapping.addTargetForeignKeyFieldName("ADDRESS.CUSTOMER_ID", "CUSTOMER.CUSTOMER_ID");)
    Any help would be appreciated.
    Thanks,
    Kevin

    Kevin,
    I spoke too soon. All you need to do is use the getAllowingNull in the ordering expression and not use the addJoinedAttribute. With this you can use query-by-example with additional outer-joined ordering.
    Here is an example based on the Employee demo:
    ReadAllQuery raq = new ReadAllQuery(Employee.class);
    ExpressionBuilder eb = raq.getExpressionBuilder();
    raq.addOrdering(eb.getAllowingNull("address").get("city").ascending());
    Employee exampleEmp = new Employee();
    exampleEmp.setLastName("%");
    // My default constructor populates the period so I'll null them so
    // they are not included in the selection criteria of the example object
    exampleEmp.getPeriod().setStartDate(null);
    exampleEmp.getPeriod().setEndDate(null);
    QueryByExamplePolicy policy = new QueryByExamplePolicy();
    policy.addSpecialOperation(String.class, "like");
    raq.setQueryByExamplePolicy(policy);
    raq.setExampleObject(exampleEmp);
    List emps = (List) session.executeQuery(raq);
    I hope this helps,
    Doug

Maybe you are looking for

  • New MacBook Air does't show youtube completely in new tab

    I just bought this MacBook Air yesterday. But I found out that the youtube always does't show the video cover whenever I open a new tab, and the comment session below the video always show loading. May I know what is the problem? What can I do to fix

  • JDBC, Oracle: access denied

    I can load Oracle driver Class.forName("oracle.jdbc.driver.OracleDriver"); But in this string: String url = "jdbc:oracle:thin:@195.52.61.6:1521:ORCL"; java.sql.Connection con = java.sql.DriverManager.getConnection(url, "SCOTT", "TIGER"); happens exce

  • Undo operation on iPad..

    Has anyone noticed that the Undo operation on iPad is same as iPhone, which means you have to shake the device to undo? Shaking an iPhone is fine but very awkward for iPad give the size of the device. Needless to say, Shake to Undo is not intuitive f

  • SAP Netweaver V12 ABAP Trial Version Cleanup Tool

    SAPNW7.0ABAPTrialSP12\regCleanTool sapstartsrv remove entries. parameters NSP 00 Anyone else having the same problem. The cleanup tool which actually doesn't cleanup the registry. This is extremely annoying as there must be 200 + entries to manually

  • Using iPod video on a new computer - without software?

    I recently bought a new laptop and I wanted to be able to use my iPod Video on it. The only problem is that I lost the CD that came with the package. Will I still be able to hook the iPod to the laptop without losing any of the songs/movies/pictures