Oracle BI Joins

Hi all,
I have two tables and there is no direct join between them in physical or logical layer, but there is a few indirect joins through a few tables.
When I put these tables in one report in presentation services, it doesn't give an error. From query log I can see that it joined these tables one using one of tables between. What I want to understand is how it decides the join. If there is more then one path between tables how it decides to go.

Hi seth2,
I think if you have more than one way to go in you table, then OBIEE will produce an error.
It is recommended that you use table aliases frequently to eliminate extraneous joins, including the following:
* Eliminate all physical joins that cross dimensions (inter-dimensional circular joins) by using aliases.
* Eliminate all circular joins (intra-dimensional circular joins) in a logical table source in the Physical Model by creating physical table aliases.
Come from here : http://download.oracle.com/docs/cd/E12103_01/books/admintool/admintool_RepositorySetup7.html
If you have more than one logical table source in the business model layer then obiee will choose the table which have the lowest grain defined. Obiee call this an Aggregate Navigation :
http://gerardnico.com/wiki/dat/obiee/bi_server/design/fact_table/obiee_query_rewrite
Regards
Nico

Similar Messages

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

  • Oracle outer join strange results (at least for me)

    Hi there,
    I want to show you a problem I saw to a client site.
    Oracle 9.2.0.8.0
    SunOS 5.9 (but I'm unable to check installed patch)
    The query is quite simple:
    SELECT *
      FROM     (SELECT /*+ NO_MERGE */
                      DISTINCT col1,col2
                  FROM Tab1
                 WHERE status = 'L') a
           LEFT JOIN
               (SELECT col1,
                       col2,
                       1 as flag_match
                  FROM tab2 a
                 WHERE     a.action IN ('I', 'U')
                       AND NVL (a.col3, 'D') IN ('I', 'U')
                       AND NVL (a.col4, '?') NOT IN ('V', 'P', 'Q')) b
           ON (b.col1 = a.col1 AND b.col2 = a.col2)The expected result is (obvious?):
    a.Col1   a.Col2   b.Col1   b.Col2   flag_match
    X          Y         NULL    NULL     NULL
    A          B         A         B          1What we get is:
    a.Col1   a.Col2   b.Col1   b.Col2   flag_match
    X          Y         NULL    NULL     NULL
    A          B         A         B          NULLThis looks wrong to me.
    If we check with a SELECT COUNT(*) the result of the query, using something like this:
    SELECT COUINT(*) FROM (
    SELECT *
      FROM     (SELECT /*+ NO_MERGE */
                      DISTINCT col1,col2
                  FROM Tab1
                 WHERE status = 'L') a
           LEFT JOIN
               (SELECT col1,
                       col2,
                       1 as flag_match
                  FROM tab2 a
                 WHERE     a.action IN ('I', 'U')
                       AND NVL (a.col3, 'D') IN ('I', 'U')
                       AND NVL (a.col4, '?') NOT IN ('V', 'P', 'Q')) b
           ON (b.col1 = a.col1 AND b.col2 = a.col2)
    WHERE flag_match...We got these results:
    with FLAG_MATCH IS NULL, 1000 rows
    with FLAG_MATCH IS NOT NULL, 900 rows
    without the where on FLAG_MATCH, 1000 rows
    What you think? Ever seen something like this?
    Thank you in advance.
    Antonio

    Hi Antonio,
    running the query as you have posted, you should not get the result NULL under column flag_match when b.col1 is not NULL.
    Unless a bug but I doubt it.
    Could you please post some sample data to be able to reproduce the problem?
    Data can be posted also as WITH statement in this way:
    WITH tab1(col1, col2, status) AS
       SELECT 'X', 'Y', 'L' FROM DUAL UNION ALL
       SELECT 'A', 'B', 'L' FROM DUAL
    , tab2(col1, col2, col3, col4, action) as
       SELECT 'A', 'B', 'I', 'X', 'I' FROM DUAL
    SELECT *
      FROM     (SELECT /*+ NO_MERGE */
                      DISTINCT col1,col2
                  FROM Tab1
                 WHERE status = 'L') a
           LEFT JOIN
               (SELECT col1,
                       col2,
                       1 as flag_match
                  FROM tab2 a
                 WHERE     a.action IN ('I', 'U')
                       AND NVL (a.col3, 'D') IN ('I', 'U')
                       AND NVL (a.col4, '?') NOT IN ('V', 'P', 'Q')) b
           ON (b.col1 = a.col1 AND b.col2 = a.col2)
    COL1 COL2 COL1_1 COL2_1 FLAG_MATCH
    A    B    A      B               1
    X    Y                            Also try to execute the statement above to see if you are experiencing the same problem.
    Edit:
    I've seen the second part of your post:
    with FLAG_MATCH IS NULL, 1000 rows
    with FLAG_MATCH IS NOT NULL, 900 rows
    without the where on FLAG_MATCH, 1000 rowsand I have to say that is looks like a bug. Could you try grouping by flag_match?
    SELECT flag_match, COUNT(*) FROM (
    SELECT *
      FROM     (SELECT /*+ NO_MERGE */
                      DISTINCT col1,col2
                  FROM Tab1
                 WHERE status = 'L') a
           LEFT JOIN
               (SELECT col1,
                       col2,
                       1 as flag_match
                  FROM tab2 a
                 WHERE     a.action IN ('I', 'U')
                       AND NVL (a.col3, 'D') IN ('I', 'U')
                       AND NVL (a.col4, '?') NOT IN ('V', 'P', 'Q')) b
           ON (b.col1 = a.col1 AND b.col2 = a.col2)
    GROUP by flag_matchRegards.
    Al
    Edited by: Alberto Faenza on Dec 18, 2012 2:49 PM

  • Oracle outer join on  multiple tables throws error

    Hi ,
    We are using ansi joins with outer joins on multiple tables in oracle 9i.
    Now these queries have to be used in Oracle8i.
    Since Oracle8i does not support ansi sql we are replacing the ansi sql queries with the oracle joins.
    On trying the same we found that the following query
    select *from tab1 a, tab2 b, tab3 c where a.c1 = b.col1(+) and c.c2 = b.col2 (+)
    throws the error
    ORA-01417: a table may be outer joined to at most one other table.
    Is there a way to simulate this query without using the outer joins on multiple tables?
    thanks

    Try writing the query in this form:
    select * from
    (select t1.col1, t1.col2
    from schema.table1 t1, schema.table2 t2
    where t1.col1 = t2.col1(+)) t4,
    schema.table3 t3 where t4.col2 = t3.col2(+)
    In the subquery, you will have to list all the columns you want to see, and you will need to provide unique aliases for any columns with duplicate names. I tested this on 9i, and don't have an 8i system to work with, so I hope this helps.

  • Oracle Equi Join Query

    Can sombody tell me the difference betweeen Query 1 * Query 2. They give the same result. Let me know keeping performance in mind which one should be used.
    create table x (id number, name varchar2(100))
    create table y (id number, name varchar2(100))
    create table z (id number, name varchar2(100))
    insert into x values(1,'test1')
    insert into x values(2,'test2')
    insert into x values(3,'test3')
    insert into x values(4,'test4')
    insert into y values(1,'test5')
    insert into y values(3,'test6')
    insert into z values(1,'test7')
    insert into z values(4,'test8')
    QUERY1
    select x.id,y.id,z.id,x.name,y.name,z.name
    from x,y,z
    where
    x.id = y.id
    and x.id = z.id
    and (x.id =2 or x.id = 1)
    QUERY2
    select x.id,y.id,z.id,x.name,y.name,z.name
    from x
    JOIN y
    ON x.id = y.id
    JOIN z
    ON x.id = z.id
    and (x.id =2 or x.id = 1)

    Sorry i forgot the integrity constraints:
    create table x (id number, name varchar2(100))
    create table y (id number, name varchar2(100))
    create table z (id number, name varchar2(100))
    alter table x add constraint x_pk primary key(id)
    alter table y add constraint y_fk foreign key(id)
    REFERENCES X(ID)
    alter table z add constraint z_fk foreign key(id)
    REFERENCES X(ID)
    insert into x values(1,'test1')
    insert into x values(2,'test2')
    insert into x values(3,'test3')
    insert into x values(4,'test4')
    insert into y values(1,'test5')
    insert into y values(3,'test6')
    insert into z values(1,'test7')
    insert into z values(4,'test8')
    select x.id,y.id,z.id,x.name,y.name,z.name
    from x,y,z
    where
    x.id = y.id
    and x.id = z.id
    and (x.id =2 or x.id = 1)
    select x.id,y.id,z.id,x.name,y.name,z.name
    from x
    JOIN y
    ON x.id = y.id
    JOIN z
    ON x.id = z.id
    and (x.id =2 or x.id = 1)

  • Oracle left join

    e.g. i have 2 table
    table_a
    subject
    math
    phy
    chem
    bio
    table_b
    subject member
    math peter
    phy peter
    phy john
    bio tim
    1) i create a view as follow:
    create or replace view view_test
    (subject,
    member)
    as select a.subject,
    b.member
    from table_a a
    left outer join table_b b
    on (a.subject = b.subject)
    how i can get the result from view when the sql is
    select * from view_test where member = 'tim';
    subject member
    math
    phy
    chem
    bio tim
    i can do it in sql statment as follow;
    select a.subject,
    b.member
    from table_a a
    left outer join table_b b
    on (a.subject = b.subject and
    b.member = 'tim')

    What part of it doesn't work for you?
    SQL> SELECT * FROM tablea;
    SUBJECT
    math
    phy
    chem
    bio
    SQL> SELECT * FROM tableb;
    SUBJECT    MEMBER
    math       peter
    phy        peter
    phy        john
    bio        tim
    SQL> CREATE VIEW view_test AS
      2  SELECT a.subject, b.member
      3  FROM tablea a
      4       LEFT OUTER JOIN tableb b
      5       ON (a.subject = b.subject);
    View created.
    SQL> SELECT *
      2  FROM view_test
      3  WHERE member = 'tim';
    SUBJECT    MEMBER
    bio        timJohn

  • Using functions in select statement(joining 5 tables) taking long time in Oracle

    Hi,
    I have created a query in oracle which joins 5 tables and uses two functions(function names are 'ca_concat' and 'ca_concat_noseq').
    Query takes approximately 40 secs to execute around 12000 records. If I remove the functions from query it excutes within a second..
    Note : I have used the oracle SQL Developer for testing the query.
    It would be appriciated if anybody helps me to improve the perfomance of the query.
    Below are the querie with and without functions:
    1. Query with functions:
    select
    imsAuditEvent12.id as ID,
    imsAuditEvent12.audit_time as AUDIT_TIME,
    imsAuditEvent12.admin_dn as ADMIN_DN,
    imsAuditEvent12.admin_name as ADMIN_NAME,
    imsAuditEvent12.event_name as EVENT_NAME,
    imsAuditEvent12.event_description as EVENT_DESCRIPTION,
    imsAuditEvent12.event_state as EVENT_STATE,
    imsAuditEvent12.envname as ENVNAME,
    imsAuditTaskSession12.task_name as TASK_NAME,
    imsAuditTaskSession12.id as TASK_ID,
    imsAuditTaskSession12.task_description as TASK_DESCRIPTION,
    imsAuditTaskSession12.task_priority as TASK_PRIORITY,
    S1.OBJECT_ID,
    S1.OBJECT_NAME as OBJECT_NAME,
    S1.OBJECT_TYPE as OBJECT_TYPE,
    S2.ATTRIBUTE_NAME as ATTRIBUTE_NAME,
    S2.ATTRIBUTE_OLDVALUES as ATTRIBUTE_OLDVALUES,
    S2.ATTRIBUTE_NEWVALUES as ATTRIBUTE_NEWVALUES,
    S3.OBJECT_DN as OBJECT_DN,
    S3.OBJECT_TYPE as IMSOBJECT_TYPE,
    S3.CONTAINER_NAME as CONTAINER_NAME,
    S3.CONTAINER_DN as CONTAINER_DN,
    S3.CONTAINER_TYPE as CONTAINER_TYPE
    from
    imsAuditEvent12 LEFT JOIN imsAuditTaskSession12 ON imsAuditTaskSession12.id=imsAuditEvent12.tasksession_id LEFT JOIN
    (select parent_event_id,
    ca_concat('imsAuditEventObject12.parent_event_id',parent_event_id,'imsAuditEventObject12.object_name','imsAuditEventObject12') as OBJECT_NAME,
    ca_concat('imsAuditEventObject12.parent_event_id',parent_event_id,'imsAuditEventObject12.object_type','imsAuditEventObject12') as OBJECT_TYPE,
    ca_concat_noseq('imsAuditEventObject12.parent_event_id',parent_event_id,'imsAuditEventObject12.ID','imsAuditEventObject12') as OBJECT_ID
    from
    imsAuditEventObject12 group by parent_event_id) S1
    ON imsAuditEvent12.id = S1.parent_event_id LEFT JOIN
    (select
    parent_object_id,
    ca_concat('parent_object_id',parent_object_id,'attribute_name','imsauditobjectattributes12') as ATTRIBUTE_NAME,
    ca_concat('parent_object_id',parent_object_id,'attribute_oldvalue','imsauditobjectattributes12') as ATTRIBUTE_OLDVALUES ,
    ca_concat('parent_object_id',parent_object_id,'attribute_newvalue','imsauditobjectattributes12') as ATTRIBUTE_NEWVALUES
    from
    imsauditobjectattributes12 group by parent_object_id) S2
    ON S1.OBJECT_ID = S2.parent_object_id LEFT JOIN
    (select
    parent_event_id,
    ca_concat('parent_event_id',parent_event_id,'OBJECT_DN','imsauditobjectrelationship12') as OBJECT_DN,
    ca_concat('parent_event_id',parent_event_id,'OBJECT_TYPE','imsauditobjectrelationship12') as OBJECT_TYPE ,
    ca_concat('parent_event_id',parent_event_id,'CONTAINER_NAME','imsauditobjectrelationship12') as CONTAINER_NAME,
    ca_concat('parent_event_id',parent_event_id,'CONTAINER_DN','imsauditobjectrelationship12') as CONTAINER_DN,
    ca_concat('parent_event_id',parent_event_id,'CONTAINER_TYPE','imsauditobjectrelationship12') as CONTAINER_TYPE
    from
    imsauditobjectrelationship12 group by parent_event_id) S3
    ON imsAuditEvent12.id =S3.parent_event_id where imsauditevent12.id > 0 and imsauditevent12.id <12000 order by imsauditevent12.id ASC;
    2. Query without using functions:
    select * from imsauditeventobject12 left join imsauditevent12 on imsauditeventobject12.id=imsauditevent12.id left join imsauditobjectattributes12 on imsauditeventobject12.id=imsauditobjectattributes12.parent_object_id left join imsaudittasksession12 on imsauditevent12.tasksession_id=imsaudittasksession12.id left join imsAuditObjectRelationship12 on imsAuditEvent12.id =imsAuditObjectRelationship12.parent_event_id where imsauditevent12.id >0 and imsauditevent12.id < 12000 order by imsauditevent12.id asc;
    Thanks,
    Badri

    Hi,
    Please find the below more information about the query.
    DB version: Oracle 11g Enterprise Edition Release 11.2.0.1.0
    Below are source of the functions:
    create or replace function ca_concat( ca_key_name in varchar2,
                           ca_key_val  in varchar2,
                           ca_other_col_name in varchar2,
                           ca_tname     in varchar2 )
       return varchar2
          as
           type rc is ref cursor;
           l_str    varchar2(32000);
           l_sep    varchar2(1);
           l_val    varchar2(32000);
           l_count   number(6);
           l_cur    rc;
       begin
       l_count :=1;
       l_str := '';
           open l_cur for 'select '|| ca_other_col_name ||'
                             from '|| ca_tname || '
                            where ' || ca_key_name || ' = '
                       using ca_key_val;
           loop
               fetch l_cur into l_val;
               l_val := SUBSTR(l_val,0,102);
               exit when (l_cur%notfound or l_count > 38);
               l_str := l_str || l_sep || l_count || '.' || l_val;
               l_sep := ',';
           l_count := l_count + 1;
           end loop;
           close l_cur;
           return l_str;
       end;
      create or replace function ca_concat_noseq( ca_key_name in varchar2,
                           ca_key_val  in varchar2,
                           ca_other_col_name in varchar2,
                           ca_tname     in varchar2 )
       return varchar2
          as
           type rc is ref cursor;
           l_str    nvarchar2(32000);
           l_sep    varchar2(1);
           l_val    varchar2(32000);
           l_count   number(6);
           l_cur    rc;
       begin
       l_count :=1;
           open l_cur for 'select '||ca_other_col_name||'
                             from '|| ca_tname || '
                            where ' || ca_key_name || ' = '
                       using ca_key_val;
           loop
               fetch l_cur into l_val;
               exit when (l_cur%notfound or length(l_val)>3000 or l_count>1);
               l_str := l_str || l_sep || l_val ;
               l_sep := ',';
           l_count := l_count + 1;
           end loop;
           close l_cur;
           return l_str;
    end;
    Below are the tables structures:
    DESC imsauditevent12;
    Name                           Null     Type                                                                                                                                                                                      
    ID                             NOT NULL NUMBER                                                                                                                                                                                       
    TASKSESSION_ID                 NOT NULL NUMBER                                                                                                                                                                                       
    TASKSESSION_OID                         VARCHAR2(100)                                                                                                                                                                                
    PARENT_EVENT_OID                        VARCHAR2(100)                                                                                                                                                                                
    AUDIT_TIME                     NOT NULL TIMESTAMP(6)                                                                                                                                                                                 
    EVENT_OID                      NOT NULL VARCHAR2(100)                                                                                                                                                                                
    ADMIN_DN                       NOT NULL VARCHAR2(512)                                                                                                                                                                                
    ADMIN_NAME                              VARCHAR2(255)                                                                                                                                                                                
    EVENT_NAME                     NOT NULL VARCHAR2(255)                                                                                                                                                                                
    EVENT_DESCRIPTION                       VARCHAR2(4000)                                                                                                                                                                               
    EVENT_STATE                             VARCHAR2(100)                                                                                                                                                                                
    ENVNAME                        NOT NULL VARCHAR2(100)                                                                                                                                                                                
    ENV_OID                        NOT NULL VARCHAR2(100)                                                                                                                                                                                
    DESC imsauditeventobject12;
    Name                           Null     Type                                                                                                                                                                                         
    ID                             NOT NULL NUMBER                                                                                                                                                                                       
    PARENT_EVENT_ID                NOT NULL NUMBER                                                                                                                                                                                       
    AUDIT_TIME                     NOT NULL TIMESTAMP(6)                                                                                                                                                                                 
    OBJECT_TYPE                    NOT NULL VARCHAR2(100)                                                                                                                                                                                
    OBJECT_NAME                             VARCHAR2(255)                                                                                                                                                                                
    DESC imsauditobjectattributes12;
    Name                           Null     Type                                                                                                                                                                                         
    ID                             NOT NULL NUMBER                                                                                                                                                                                       
    PARENT_OBJECT_ID               NOT NULL NUMBER                                                                                                                                                                                       
    AUDIT_TIME                     NOT NULL TIMESTAMP(6)                                                                                                                                                                                 
    DISPLAY_NAME                            VARCHAR2(255)                                                                                                                                                                                
    ATTRIBUTE_NAME                 NOT NULL VARCHAR2(255)                                                                                                                                                                                
    ATTRIBUTE_OLDVALUE                      VARCHAR2(4000)                                                                                                                                                                               
    ATTRIBUTE_NEWVALUE                      VARCHAR2(4000)                                                                                                                                                                               
    DESC imsaudittasksession12;
    Name                           Null     Type                                                                                                                                                                                         
    ID                             NOT NULL NUMBER                                                                                                                                                                                       
    PARENT_TS_OID                           VARCHAR2(100)                                                                                                                                                                                
    PARENT_EVENT_OID                        VARCHAR2(100)                                                                                                                                                                                
    AUDIT_TIME                     NOT NULL TIMESTAMP(6)                                                                                                                                                                                 
    TASKSESSION_OID                NOT NULL VARCHAR2(100)                                                                                                                                                                                
    ADMIN_DN                       NOT NULL VARCHAR2(512)                                                                                                                                                                                
    ADMIN_NAME                              VARCHAR2(255)                                                                                                                                                                                
    TASK_NAME                               VARCHAR2(255)                                                                                                                                                                                
    TASK_TAG                       NOT NULL VARCHAR2(255)                                                                                                                                                                                
    TASK_DESCRIPTION                        VARCHAR2(4000)                                                                                                                                                                               
    TASK_PRIORITY                           NUMBER                                                                                                                                                                                       
    STATE                          NOT NULL VARCHAR2(100)                                                                                                                                                                                
    ENVNAME                        NOT NULL VARCHAR2(100)                                                                                                                                                                                
    ENV_OID                        NOT NULL VARCHAR2(100)                                                                                                                                                                
    DESC imsAuditObjectRelationship12;
    Name                           Null     Type                                                                                                                                                                                         
    ID                             NOT NULL NUMBER                                                                                                                                                                                       
    PARENT_EVENT_ID                NOT NULL NUMBER                                                                                                                                                                                       
    AUDIT_TIME                     NOT NULL TIMESTAMP(6)                                                                                                                                                                                 
    OBJECT_TYPE                    NOT NULL VARCHAR2(100)                                                                                                                                                                                
    OBJECT_DN                      NOT NULL VARCHAR2(512)                                                                                                                                                                                
    CONTAINER_TYPE                 NOT NULL VARCHAR2(100)                                                                                                                                                                                
    OBJECT_NAME                    NOT NULL VARCHAR2(255)                                                                                                                                                                                
    CONTAINER_NAME                 NOT NULL VARCHAR2(255)                                                                                                                                                                                
    CONTAINER_DN                   NOT NULL VARCHAR2(512)                                                                                                                                                                          
    OPERATION                      NOT NULL VARCHAR2(50)                                                                                                                                                                                 
    Thanks,
    Badri

  • Outer join query for SQL server from Oracle

    Hi All,
    My question is regarding making queries from Oracle to SQL Server database thorugh DBLink.
    In my oracle database I have a DBLink emp.world for SQL Server database.
    I need to query SQL Server data from oracle (so that this query can be combined with other oracle tables).
    Query is given below:
    SELECT
            a."EmpID" as "Employee ID",
            a."EmpStatus" "Employee Status"
            b."EmpSub" as "Employee Subjects"
    FROM
            [email protected] a
            left outer join [email protected] b on a."EmpID" = b."suEmpID"
    ORDER BY  a."EmpID";My problem is when I run the same query from oracle, it does not show the EmpID that does not exist in Subjects table, but when run from actual SQL Server database, it shows all the records.
    Samples are given below:
    Run from Oracle
    Employee ID      Employee Status     Employee Subjects
    101                     Active                     Maths
    102                     Active                     Maths
    102                     Active                     Physics
    104                   Inactive                  Chemistry
    Run form SQL Server
    Employee ID      Employee Status     Employee Subjects
    101                     Active                     Maths
    102                     Active                     Maths
    102                     Active                     Physics
    103                 Active                       NULL
    104             Inactive            ChemistryI am not sure why in oracle outer join for SQL server tables is not working. What is the right way for outer join in this case.
    I am using oracle database 10gR2 and SQL Server 2005.
    Please Help.
    Thanks.

    SELECT
    a."EmpID" as "Employee ID",
    a."EmpStatus" "Employee Status"
    b."EmpSub" as "Employee Subjects"
    FROM
    [email protected] a
    left outer join [email protected] b on a."EmpID" = b."suEmpID"
    ORDER BY a."EmpID";
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm#sthref3175
    From your description, it appears you may need a right outer join. You want to get back all the rows from 'B', not from 'A'. Try a right join and let us know.

  • Outer join with Oracle Syntax

    Hi, i'm new in oracle and ihave been working this query for reports for about 2 weeks, plz take a look on my query
    SELECT mmt.transaction_date "Transaction Date",
                msib.segment1 "Item",
                gcc.segment1||'-'||gcc.segment2||'-'||gcc.segment3||'-'||gcc.segment4||'-'||gcc.segment5||'-'||gcc.segment6||'-'||(nvl(gcc.segment7,'000000')) "account",
                (CASE mttype.transaction_type_name
                WHEN 'Average cost update' THEN
              ((nvl(mmt.new_cost,0) - nvl(mmt.prior_cost,0)) * nvl(mmt.quantity_adjusted,0)) + nvl(mmt.variance_amount,0)
                ELSE
                 (mmt.Primary_quantity * nvl(mmt.actual_cost, 0) + nvl(mmt.variance_amount, 0))
               END) "Transaction Value",
                mttype.description "Transaction Type",
                mmt.subinventory_code "Subinventory",
                ood.organization_code "Org",
                msib.Primary_UOM_Code "UOM",
                mmt.Primary_Quantity "Primary Quantity",
                mtr.description "Reason",
                mmt.transaction_reference "Reference"
    FROM mtl_material_transactions mmt,
             mtl_system_items_b msib,
             mtl_transaction_accounts mta,
             gl_code_combinations gcc,
             mtl_transaction_types mttype,
             Org_Organization_Definitions ood,
             mtl_transaction_reasons mtr
    WHERE mmt.transaction_date >= :P_DATE_FROM
               and mmt.transaction_date  < :P_DATE_TO +1
               and mmt.organization_id = :P_ORGANIZATION
               and msib.organization_ID = mmt.organization_ID 
               and msib.inventory_item_id=mmt.inventory_item_id
               and mta.transaction_id=mmt.transaction_id
               and gcc.code_combination_id = mta.reference_account
               and mttype.transaction_type_id=mmt.transaction_type_id
               and mmt.reason_id=mtr.reason_id(+)
               and ood.organization_id=mmt.organization_id
               and mttype.transaction_type_id = :P_TRANSACTION_TYPE
               and msib.segment1 = :P_ITEM
               AND gcc.segment2 = :P_ACCOUNTthe null values is on the mtl_material_transactions table, which is reason_id, subinventory_code, and transaction_reference
    the desired out put would be to show all the record on mtl_material_transactions with the null values
    so, did i put the right symbol for the outer join ??
    btw
    i have tried put the (+) on various places but it still no good, and i'm really at a loss

    user11174063 wrote:
    Hi, i'm new in oracle and ihave been working this query for reports for about 2 weeks, plz take a look on my query
    SELECT mmt.transaction_date "Transaction Date",
    msib.segment1 "Item",
    gcc.segment1||'-'||gcc.segment2||'-'||gcc.segment3||'-'||gcc.segment4||'-'||gcc.segment5||'-'||gcc.segment6||'-'||(nvl(gcc.segment7,'000000')) "account",
    (CASE mttype.transaction_type_name
    WHEN 'Average cost update' THEN
    ((nvl(mmt.new_cost,0) - nvl(mmt.prior_cost,0)) * nvl(mmt.quantity_adjusted,0)) + nvl(mmt.variance_amount,0)
    ELSE
    (mmt.Primary_quantity * nvl(mmt.actual_cost, 0) + nvl(mmt.variance_amount, 0))
    END) "Transaction Value",
    mttype.description "Transaction Type",
    mmt.subinventory_code "Subinventory",
    ood.organization_code "Org",
    msib.Primary_UOM_Code "UOM",
    mmt.Primary_Quantity "Primary Quantity",
    mtr.description "Reason",
    mmt.transaction_reference "Reference"
    FROM mtl_material_transactions mmt,
    mtl_system_items_b msib,
    mtl_transaction_accounts mta,
    gl_code_combinations gcc,
    mtl_transaction_types mttype,
    Org_Organization_Definitions ood,
    mtl_transaction_reasons mtr
    WHERE mmt.transaction_date >= :P_DATE_FROM
    and mmt.transaction_date  < :P_DATE_TO +1
    and mmt.organization_id = :P_ORGANIZATION
    and msib.organization_ID = mmt.organization_ID 
    and msib.inventory_item_id=mmt.inventory_item_id
    and mta.transaction_id=mmt.transaction_id
    and gcc.code_combination_id = mta.reference_account
    and mttype.transaction_type_id=mmt.transaction_type_id
    and mmt.reason_id=mtr.reason_id(+)
    and ood.organization_id=mmt.organization_id
    and mttype.transaction_type_id = :P_TRANSACTION_TYPE
    and msib.segment1 = :P_ITEM
    AND gcc.segment2 = :P_ACCOUNTthe null values is on the mtl_material_transactions table, which is reason_id, subinventory_code, and transaction_reference
    the desired out put would be to show all the record on mtl_material_transactions with the null values
    so, did i put the right symbol for the outer join ??
    btw
    i have tried put the (+) on various places but it still no good, and i'm really at a losshttp://www.lmgtfy.com/?q=oracle+outer+join+example

  • Converting oracle join to Ansi sql join

    Hi Guys,
    I am new to SQL and trying to convert the following Oracle query (joins) into ANSI sql joins...Can someone please help me?
    SELECT M.EXTERNALCODE, M.NAME AS MNAME, SC.BIRIM, SM.TRANSACTIONDATE, SMD.AMOUNT,
    SMD.UNITPRICE, SM.ID AS SMID, SMD.ID AS SMDID, F.NAME AS FNAME,
    IFNULL (SMD.AMOUNT, 0, SMD.AMOUNT) * IFNULL (SMD.UNITPRICE, 0, SMD.UNITPRICE) AS TOTALPRICE, SMD.AMOUNT AS RECEIVED_QUANTITY,
    PD.ORDERID, PD.AMOUNT QUANTITY, PO.PROCESSDATE
    FROM STOCKMAINTRANSACTION SM,
    STOCKMAINTRANSACTIONDETAIL SMD,
    MATERIAL M,
    STOCKCARD SC,
    FVSTOCK FVS,
    FIRM F,
    PURCHASEORDER PO,
    PURCHASEORDERDETAIL PD,
    PURCHASEORDERDETAILSUPPLIED PDS
    WHERE SM.ID = SMD.MAINTRANSACTIONID
    AND SMD.MATERIALID = M.ID
    AND SMD.STOCKCARDID = SC.ID
    AND SM.PROPREF = FVS.RECORDID(+)
    AND FVS.FIELDID(+) = 2559
    AND FVS.FLEVEL(+) = 'F'
    AND F.ID(+) = SUBSTR (FVS.FVALUE, 1, 9)
    AND SM.TRANSDEFID in (999,2329,2344,2370,150000903,150005362)
    AND SMD.CANCELLED = 0
    AND SMD.STOCKUPDATED = 1
    AND SMD.ID = PDS.STOCKMAINTRANSACTIONDETAILID
    AND PDS.ORDERDETAILID = PD.ORDERDETAILID
    AND PO.ORDERID = PD.ORDERID
    AND (M.ID = {@MATERIALID@} OR {@MATERIALID@} = 0)
    AND (SM.STOREID = {@STOREID@} OR {@STOREID@} = 0)
    AND (F.ID = {@SUPPLIERID@} OR {@SUPPLIERID@} = 0)
    AND SM.TRANSACTIONDATE BETWEEN {@STARTDATE@} AND {@ENDDATE@}
    ORDER BY F.NAME, M.EXTERNALCODE, SM.TRANSACTIONDATE
    Really appreciate the help!
    Thanks.

    Hi,
    Welcome to the forum!
    To convert to ANSI syntax, replace join conditions in the WHERE clause
    FROM           x
    ,             y
    WHERE         x.x1  = y.y1
    AND           x.x2  = y.y2with ON conditions in the FROM clause:
    FROM           x
    JOIN             y   ON    x.x1  = y.y1
                             AND   x.x2  = y.y2In inner joins, conditions that do not reference 2 tables are not really join conditions, so it doesn't matter if they are in the FROM clause or in the WHERE clause.
    In your case
    SM.TRANSDEFID in (999,2329,2344,2370,150000903,150005362)could be part of a join condition involving sm, or it could be in the WHERE clause. Most people find it clearer if 1-table conditions like this are in the WHERE clause.
    Again, this only applies to inner joins. For outer joins, all conditions that apply to a table that may lack matching rows must be included in the FROM clause, like this:
    LEFT OUTER JOIN  fvstock   fvs  ON   sm.propref       = fvs.recordid
                                    AND  fvs.fieldid  = 2559
                        AND  fvs.flevel   = 'F'Try it.
    If you have trouble, post your best attempt, along with CREATE TABLE and INSERT statements for a little sample data from all the tables involved, and the results you want from that data. Simplify the problem. Post only the tables and columns that you don't know how to handle.
    See the forum FAQ {message:id=9360002}
    user8428528 wrote:
    AND (M.ID = {@MATERIALID@} OR {@MATERIALID@} = 0)
    AND (SM.STOREID = {@STOREID@} OR {@STOREID@} = 0)
    AND (F.ID = {@SUPPLIERID@} OR {@SUPPLIERID@} = 0)
    AND SM.TRANSACTIONDATE BETWEEN {@STARTDATE@} AND {@ENDDATE@}This is not valid Oracle SQL. Is {@MATERIALID@} some kind of variable?

  • Can you join two DSO's?

    We have tried joining two DSO's and are getting the warning that "more than one datasource has been used in this report". It appears that the DSO driver does not support joins. The report runs but it is VERY slow, the same sort of performance you get when you try to join data from two datasources that are actually different (like two different SQL Server databases or an Oracle table joined to a SQL Server table). It appears that this is not a supported function with the DSO driver. Any thoughts?

    Yes, we have created the joins between the two DSOs. We are looking into using the Open SQL driver to go against the base tables to see if that will work.  This is how the original ODS driver used to work.
    Update: After changing the join type to a left outer join the performance improved signficantly. Although not ideal it looks like it will be fine for our requirements. This particular report will be run monthly and scheduled to run overnight.
    Edited by: Mike Garrett on Oct 27, 2009 4:28 PM

  • Who can solve oracle error ORA-0012638 ?

    Why I get this error when I re-start oracle after join networking domain ?
    When the computer in lcoal mode ,the oracle is normal .
    How can I solve this error ?

    Hello fredovolley,
    Welcome to the HP Support Forums!
    I see that you are experiencing an error 403 with the Photosmart 5520 series. I would like to offer the steps I have given before, check them out here: Re: Trouble scanning using Photosmart 6520
    Even though it states it is for a 6520, the steps are all the same. I hope this help, cheers!
    JERENDS
    I work on behalf of HP
    Please click “Accept as Solution” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos Thumbs Up" to the left of the reply button to say “Thanks” for helping!

  • URGENT - need help with ansi/iso outer joins

    Hi,
    I am currently preparing for the OCP sql exam for the 9i developer track and I think a statement is printed wrong in my study book, please could somebody confirm the following:-
    Oracle Outer Join syntax
    from tab_a, tab_b
    where a.col_1 (+) = b.col_1
    ANSI/ISO Equivalent
    from tab_a a left outer join tab_b b
    on a.col_1 = b.col_1
    Should n't the above be a right outer join
    Please could somebody confirm or explain if I am wrong.
    Thanks in anticipation.
    Simon
    Note. The book is OCP Introduction to 9i sql (1Z0-007) page 115 (table 3-1) - author Jason Couchman

    It seems so....
    See
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_103a.htm#2107297

  • Data base oracle in SAP

    Hi,
    The combination of all dimension id's ideally make the primary(composite) key of the fact table.
    it seems that there is a database restriction of 16 fields to be combined to make a joint primary key.
    I heard that Oracle table join relation is the restriction of 16. I mean foregn key relations from a table ( fact table ) can not exceede 16. and thus we have 16 dimensions as the restriction..
    It is ORacle limitation.. ( data base )
    Any data base can not have more than 16 Fields as primary key in a table and hence 16 dimentions as MAX limit..for our facttable / cube.In database tables level we have only 16 primary keys, thats the reason why we hav 16 dimensions in infocube.
    ( remember oracle is the database we use for SAP ).
    Rds
    vairava ganesh.G

    Yes, you understand the issue.  Not sure about all the other DBs, I think they have 16 column index limits as well.  Even if one of them would support more columns in the index, I doubt SAP would reengineer the BW to support them, until/unless that DB had a major portion of the BW installations.

  • Left Outer Join Help...

    Hi Everyone,
    I am still in the process of learning SQL, and I am having trouble specifically with the the left outer join.  I normally join tables using equijoin's, but I am not getting the right data set returns, and thought the using a left or right outer join would resolve the problem...
    Here is my SQL that is working properly with 1 left outer join.  I am building the query slowly so in the next SQL you will see where I am seeing the error.  I don't expect you to understand the data and columns I am trying to join, I believe the problems I am experiencing are related to syntax, and I am hoping you can find where my syntax errors are.
    select
      s.name as "Screen Name",
      sv.view_name as "View Name",
      s_view.name
    from
      s_screen s,
      s_screen_view sv
      left outer join s_view
      ON (sv.view_name = s_view.name)
    where
      sv.screen_id = '1-866A-1X3LU' and
      s.row_id = sv.screen_id and
      s.repository_id = '1-866A-1' and
      s_view.repository_id = '1-866A-1';
    Here is the SQL where I am experiencing the following error...
    Error:
    ORA-00904: "SV"."VIEW_NAME": invalid identifier
    00904. 00000 -  "%s: invalid identifier"
    *Cause:   
    *Action:
    Error at Line: 14 Column: 7
    Problematic SQL:
    select
      s.name as "Screen Name",
      sv.view_name as "View Name",
      s_view.name,
      s_applet.name as Applet
      --a.name as "Applet Name"
    from
      s_screen s,
      s_screen_view sv,
      s_view_wtmpl_it wti
      left outer join s_view
      ON (sv.view_name = s_view.name)
      left outer join s_applet
      ON (wti.name = s_applet.name)
    where
      sv.screen_id = '1-866A-1X3LU' and
      s.row_id = sv.screen_id and
      s.repository_id = '1-866A-1' and
      s_view.repository_id = '1-866A-1';
    Thanks in advance for your help.
    Chris

    Hi,
    cjpicc11 wrote:
    What is an Oracle style join vs. ANSI join?
    Would this be Oracle Style or ANSI Join?
      left outer join s_view
      ON (sv.view_name = s_view.name)
      left outer join s_applet
    Would this be Oracle Style or ANSI Join?
    s.row_id = sv.screen_id
    "Oracle style" or "old style" joins have commas between tables in the FROM clause, and the join conditions are all in the WHERE clause.  They do not use the keywords JOIN or ON.
    ANSI style joins have the keyword JOIN between tables (sometimes accompanied by other keywords, such as LEFT, OUTER or CROSS), and the join conditions are given in the FROM clause, usually after the keyword ON.
    The first example you gave is an ANSI style join.  It has the JOIN keyword, not a comma, between tables.
    The second example you gave:
    s.row_id = sv.screen_id
    could be part of either.  It could occur in an ANSI join (in the FROM clause, after the keyword ON), or it could occur in an old-style join (in the WHERE clause).

Maybe you are looking for