Problems with natural join

Hi!
I'm learning SQL and I have lot of doubts but I think with this example I can generalize them.
I have the tables:
book {idbook (PK), namebook}
auhor {idauthor (PK), nameauthor, idcountry (FK)}
authorship {idauthor (FK), idbook (FK)} (both the same constraint PK)
country {idcountry (PK), namecountry}
I want the name of the books that have authors from Canada.
I assumed that a correct query would be:
SELECT namebook FROM book NATURAL JOIN (authorship NATURAL JOIN (author NATURAL JOIN country)) WHERE country.namecountry = 'Canada';
The result that I expected was:
Book3
Book5
but this query returns me all books that have relations in authorship (with authors from any country), 2 times!! like:
book2
book3
book4
book5
book2
book3
book4
book5
the best I can do to get my correct result is:
SELECT namebook FROM book NATURAL JOIN (authorship NATURAL JOIN author) WHERE author.idcountry = 2;
But of course I can't use this one...
Does anyone can explain me what is happening?
Thanks a lot!
Edited by: user12040235 on 15/10/2009 09:37
Edited by: user12040235 on 15/10/2009 09:51

Hi,
That may be a bug.
I get the correct results (2 rows) in Oracle 10.1, but I get the same bad results you do (12 rows) in Oracle 11.1.
In Oracle 11, I get the expected results if say "SELECT *" instead of "SELECT book.namebook".
I also get the correct results if I add any of the join columns to the SELECT clause. Adding a non-join column, e.g.
SELECT  BOOK.namebook, author.nameauthor
FROM            book
...gets the wrong results.
For the benefit of anyone who wants to try this:
DROP TABLE     author;
create table     author     AS
SELECT  1 AS idauthor, 'Jose Luiz do Rego' AS nameauthor, 1 AS idcountry     FROM dual     UNION ALL
SELECT         2, 'Barbara Bela',                                      2          FROM dual     UNION ALL
SELECT         3, 'Juan Domingues',                                    5          FROM dual     UNION ALL
SELECT         4, 'José Mauro de Vasconcelos',                         1          FROM dual     UNION ALL
SELECT         5, 'Vader',                                             2          FROM dual     UNION ALL
SELECT         6, 'navathe',                                           4          FROM dual     UNION ALL
SELECT         7, 'Machado de Assis',                                  1          FROM dual
drop table     AUTHORSHIP;
CREATE TABLE     authorship     AS
SELECT         2 AS idauthor,          5 AS idbook     FROM dual     UNION ALL
SELECT         1 AS idauthor,          1 AS idbook     FROM dual     UNION ALL
SELECT         5 AS idauthor,          3 AS idbook     FROM dual     UNION ALL
SELECT         6 AS idauthor,          2 AS idbook     FROM dual     UNION ALL
SELECT         7 AS idauthor,          4 AS idbook     FROM dual     UNION ALL
SELECT         7 AS idauthor,          6 AS idbook     FROM dual;
drop table     book;
CREATE TABLE   book     AS
SELECT         1 AS idbook, 'book1' AS namebook     FROM dual     UNION ALL
SELECT         2 AS idbook, 'book2' AS namebook     FROM dual     UNION ALL
SELECT         3 AS idbook, 'book3' AS namebook     FROM dual     UNION ALL
SELECT         4 AS idbook, 'book4' AS namebook     FROM dual     UNION ALL
SELECT         5 AS idbook, 'book5' AS namebook     FROM dual     UNION ALL
SELECT         6 AS idbook, 'book6' AS namebook     FROM dual     UNION ALL
SELECT         7 AS idbook, 'book7' AS namebook     FROM dual;
DROP TABLE     country;
CREATE TABLE     country     AS
SELECT         1 AS idcountry, 'Brazil' as namecountry     FROM dual     UNION ALL
SELECT         2 AS idcountry, 'Canada' as namecountry     FROM dual     UNION ALL
SELECT         3 AS idcountry, 'Chile' as namecountry     FROM dual     UNION ALL
SELECT         4 AS idcountry, 'Venezuela' as namecountry    FROM dual     UNION ALL
SELECT         5 AS idcountry, 'USA' as namecountry          FROM dual     UNION ALL
SELECT         6 AS idcountry, 'Argentina' as namecountry    FROM dual     ;

Similar Messages

  • A simple problem with natural join

    i have 2 tables what have columns with distinct's names are referenced.
    natural join not works 'cose only foreign key reference this 2 tables.
    Have something to make table join in using an specific foreign key??
    I'm using oracle9i
    Example:
    table a( a_cod number, a_name varchar2(20))
    table b( b_cod number, b_month_year date, b_salary number)
    ALTER TABLE b ADD ( CONSTRAINT b_a_FK FOREIGN KEY (b_cod)
    REFERENCES a (a_cod));
    select * from a natural join b
    where trunc(b_month_year) = trunc(sysdate)

    I'm not express me correctly.
    We have 2 tables like this:
    CREATE TABLE PPTBA001
      PPA001_GROUP             NUMBER(3)            NOT NULL,
      PPA001_PEOPLECODE        VARCHAR2(20 BYTE)    NOT NULL,
      PPA001_NAME              VARCHAR2(60 BYTE)    NOT NULL,
      PPA001_DATEOFBIRTHDAY    DATE                 NOT NULL);
    CREATE TABLE CLTBA001
      CLA001_GROUP            NUMBER(3)             NOT NULL,
      CLA001_CLIENTCODE       VARCHAR2(20 BYTE)     NOT NULL,
      CLA001_SITUATION        NUMBER(1)             DEFAULT 1);
    SELECT * FROM PPTBA001 NATURAL JOIN CLTBA001;
    ALTER TABLE CLTBA001 ADD (
      CONSTRAINT CLA001_PPAA001_FK1 FOREIGN KEY (CLA001_GROUP, CLA001_CLIENTCODE)
        REFERENCES PPTBA001 (OFA001_GROUP,OFA001_PEOPLECODE));
          the select returns without results. 'cose does not have columns like same name.
    Natural join use a columns with same name. I need something use an foreign key.
    Why?? Now i have a problem .. i need aggregate one more column in primary key
    and i need change all selects that have join with PPTBA001 and put manualy a new column.. if have a other possibility like natural join to using a foreign key to join the selects problems is so more easy to resolve.
    Message was edited by:
    jonas.lima

  • Select distinct problem with muliple join tables, help needed

    Hi,
    I have two main tables. Each has its of sub joined tables.
    guest_id_for_reservation connects two major tables. This has
    to be that way
    because my guest may change the room status from single to
    double (and the
    similar exceptional requests).
    guests reservation
    guest_id_for_reservation
    countrytable hoteltable
    delegationtable roomtype
    I form a query. I want to select distinct those results. But
    it does not
    work.
    If I do not include any table related to reservation table
    and its sub
    joined tables (disregarding guest_id_for_reservation), it
    works.
    Is there a specific syntax for select distinct of this type
    or any
    workaround.?
    Thank you
    Hakan

    Hi I'm still battling with this - have connected the AX to my Imac via ethernet and it shows up fine in Airport Utility. Status light is green and it says its set up to connect to my existing wireless network using wireless connection. Security in Network Preferences is the same for both: WPA2 Personal.
    So I don't think there's a problem with the AX, and my current wireless network (BT Home Hub) is working fine.
    And when I restore factory settings Airport Utility can see the AX before updating settings so the wireless side of AX must work too.
    I'm figuring it must be something about the settings that mean AU can't see it anymore. But I can't work out what, since security is the same.
    Any ideas would be great!

  • Problem with outer join with filter on join column

    Hi,
    In physical layer I have one dimension and two facts, and there's an outer join between the facts.
    dim_DATE ,
    fact_1 ,
    fact_2
    Joins:
    dim_DATE inner join fact_1 on dim_DATE.DATE = fact_1.DATE
    fact_1 left outer join fact_2 on fact_1.DATE = fact_2.DATE and fact_1.SOME_ID = fact_2.SOME_ID
    When I run a report with a date as a filter, OBIEE executes "optimized" physical SQL:
    select fact1.X, fact2.Y
    from
    Fact_1 left outer join on fact_1.DATE = fact_2.DATE and fact_1.SOME_ID = fact_2.SOME_ID
    where Fact_1.DATE = TO_DATE('2009-05-28' , 'YYYY-MM-DD' )
    and  Fact_2.DATE = TO_DATE('2009-05-28' , 'YYYY-MM-DD')
    The filter on Fact_2.DATE effectively replaces outer join with inner.
    Is there a way to disable this "optimization", which is actually very good for inner joins, but doesn't allow outer joins?
    Thanks in advance,
    Alex
    Edited by: AM_1 on Aug 11, 2009 8:20 AM

    If you want to perform a Fact-based partitioning with OBIEE (two fact with the same dimension), you have to :
    * create in your physical layer for each fact table the joins with the dimension
    * create in the Business Model layer ONE star schema with ONE logical fact table containing the columns of your two physical fact table
    In this way when you choose minimal one column of your fact1 and one column of your fact2, OBIEE will perform two query against each fact table/dimension, join them with an OUTER JOIN and your problem will disappear.
    Cheers
    Nico

  • Problems with AP joining vWLC

    I am working with a vWLC on 7.4 code with a 3500i AP on 12.4(23c)JA code.  The AP is not joining the controller automatically here is the output from the AP during a join failure,
    *Jul 15 09:57:58.000: %CAPWAP-5-DTLSREQSEND: DTLS connection request sent peer_ip: 10.2.98.225 peer_port: 5246
    *Jul 15 09:57:59.000: %CAPWAP-5-CHANGED: CAPWAP changed state to
    *Jul 15 09:57:59.016: %LWAPP-3-CLIENTERRORLOG: Peer certificate verification failed
    *Jul 15 09:57:59.016: %CAPWAP-3-ERRORLOG: Certificate verification failed!
    *Jul 15 09:57:59.016: DTLS_CLIENT_ERROR: ../capwap/capwap_wtp_dtls.c:333 Certificate verified failed!
    *Jul 15 09:57:59.016: %DTLS-4-BAD_CERT: Certificate verification failed. Peer IP: 10.2.98.225
    *Jul 15 09:57:59.016: %DTLS-5-SEND_ALERT: Send FATAL : Bad certificate Alert to 10.2.98.225:5246
    *Jul 15 09:57:59.016: %DTLS-3-BAD_RECORD: Erroneous record received from 10.2.98.225: Malformed Certificate
    *Jul 15 09:57:59.016: %DTLS-5-SEND_ALERT: Send FATAL : Close notify Alert to 10.2.98.225:5246
    *Jul 15 09:57:59.016: %CAPWAP-3-ERRORLOG: Invalid event 38 & state 3 combination.
    *Jul 15 09:58:18.881: %CDP_PD-2-POWER_LOW: All radios disabled - NON_CISCO-NO_CDP_RECEIVED  (0000.0000.0000)
    From my research about this issue I should be able to do debug pm pki enable and get the SSC key hash and join the AP manually to the controller.  When I do the debug I do not see the SSC key hash, I only see,
    (Cisco Controller) >*sshpmLscTask: Jul 15 09:46:08.268: sshpmLscTask: LSC Task received a message 4
    *spamApTask1: Jul 15 09:57:58.190: 50:3d:e5:f0:dc:f1 Discovery Request from 10.2.98.3:3536
    *spamApTask1: Jul 15 09:57:58.190: 50:3d:e5:f0:dc:f1 Join Priority Processing status = 0, Incoming Ap's Priority 1, MaxLrads = 200, joined Aps =0
    *spamApTask1: Jul 15 09:57:58.190: 50:3d:e5:f0:dc:f1 Discovery Response sent to 10.2.98.3:3536
    *spamApTask1: Jul 15 09:57:58.190: 50:3d:e5:f0:dc:f1 Discovery Response sent to 10.2.98.3:3536
    *spamApTask1: Jul 15 09:58:09.121: 50:3d:e5:f0:dc:f1 DTLS connection not found, creating new connection for 10:2:98:3 (3536) 10:2:98:225 (5246)
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCID: called to evaluate <cscoDefaultIdCert>
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCID: comparing to row 0, CA cert >bsnOldDefaultCaCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCID: comparing to row 1, CA cert >bsnDefaultRootCaCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCID: comparing to row 2, CA cert >bsnDefaultCaCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCID: comparing to row 3, CA cert >bsnDefaultBuildCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCID: comparing to row 4, CA cert >cscoDefaultNewRootCaCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCID: comparing to row 5, CA cert >cscoDefaultMfgCaCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCID: comparing to row 0, ID cert >bsnOldDefaultIdCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCID: comparing to row 1, ID cert >bsnDefaultIdCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCID: comparing to row 2, ID cert >cscoDefaultIdCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCertFromCID: called to get cert for CID 1234873a
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCertFromCID: comparing to row 0, certname >bsnOldDefaultCaCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCertFromCID: comparing to row 1, certname >bsnDefaultRootCaCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCertFromCID: comparing to row 2, certname >bsnDefaultCaCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCertFromCID: comparing to row 3, certname >bsnDefaultBuildCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCertFromCID: comparing to row 4, certname >cscoDefaultNewRootCaCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCertFromCID: comparing to row 5, certname >cscoDefaultMfgCaCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCertFromCID: comparing to row 0, certname >bsnOldDefaultIdCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCertFromCID: comparing to row 1, certname >bsnDefaultIdCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCertFromCID: comparing to row 2, certname >cscoDefaultIdCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCID: called to evaluate <cscoDefaultIdCert>
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCID: comparing to row 0, CA cert >bsnOldDefaultCaCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCID: comparing to row 1, CA cert >bsnDefaultRootCaCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCID: comparing to row 2, CA cert >bsnDefaultCaCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCID: comparing to row 3, CA cert >bsnDefaultBuildCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCID: comparing to row 4, CA cert >cscoDefaultNewRootCaCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCID: comparing to row 5, CA cert >cscoDefaultMfgCaCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCID: comparing to row 0, ID cert >bsnOldDefaultIdCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCID: comparing to row 1, ID cert >bsnDefaultIdCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetCID: comparing to row 2, ID cert >cscoDefaultIdCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetSshPrivateKeyFromCID: called to get key for CID 1234873a
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetSshPrivateKeyFromCID: comparing to row 0, certname >bsnOldDefaultIdCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetSshPrivateKeyFromCID: comparing to row 1, certname >bsnDefaultIdCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetSshPrivateKeyFromCID: comparing to row 2, certname >cscoDefaultIdCert<
    *spamApTask1: Jul 15 09:58:09.121: sshpmGetSshPrivateKeyFromCID: match in row 2
    *spamApTask3: Jul 15 09:58:09.139: 50:3d:e5:f0:dc:f1 DTLS connection closed event receivedserver (10:2:98:225/5246) client (10:2:98:3/3536)
    *spamApTask3: Jul 15 09:58:09.139: 50:3d:e5:f0:dc:f1 No entry exists for AP (10:2:98:3/3536)
    *spamApTask3: Jul 15 09:58:09.139: 50:3d:e5:f0:dc:f1 No AP entry exist in temporary database for 10.2.98.3:3536
    What else can I try to get this AP to join the controller??
    Thank you.

    "configure certificate ssc hash validation disable"  didn't help, same problems
    I tried to add the AP by its MAC and MIC to the authorized APs list but it just tells me "
    50:3d:e5:f0:dc:f1 No AP entry exist in temporary database for 10.2.98.3:3536"
    The SSC key Hash still doesn't show in the debug output.  What else can I try?

  • 2 problem with BITMAP JOIN INDEX and access plan

    On my schema ("LSA") I have 3 tables:
    AAB_VENDUTO (~4.200.000 record)
    AAB_ARTICOLO (~8.200 record)
    AAB_CLIENTE (~15.000 record)
    AAB_ARTICOLO.MARCA has 1079 distinct values
    AAB_CLIENTE.TITOLO_STUDIO has 22 distinct values
    I create 2 different bitmap join index:
    CREATE BITMAP INDEX lsa.AAB_V_ARTICOLO_MARCA_IDX ON LSA.AAB_VENDUTO(MARCA)
    FROM LSA.AAB_VENDUTO vv, LSA.AAB_ARTICOLO aa WHERE vv.articolo_id=aa.articolo_id;
    CREATE BITMAP INDEX lsa.AAB_V_CLIENTE_TIT_STUDIO_IDX ON LSA.AAB_VENDUTO(TITOLO_STUDIO)
    FROM LSA.AAB_VENDUTO vv, LSA.AAB_CLIENTE cc WHERE vv.cliente_id=cc.cliente_id;(star_trasformation_enabled is TRUE)
    I run (on SQL Developer 1.5.5) these similar queries:
    SELECT DISTINCT VV.cliente_id FROM LSA.AAB_VENDUTO VV JOIN LSA.AAB_ARTICOLO AA on VV.articolo_id=AA.articolo_id
    WHERE (MARCA='ALGIDA' OR MARCA='SAMMONTANTA');
    SELECT DISTINCT VV.cliente_id FROM LSA.AAB_VENDUTO VV JOIN LSA.AAB_CLIENTE CC  on VV.cliente_id=CC.cliente_id  
    WHERE (titolo_studio='LAUREA BREVE' OR titolo_studio='MAGISTRALE');The first one use correctly the bitmap join index, this is the access plan:
    !http://bitlgs.altervista.org/_altervista_ht/marca.png!
    but the second query...
    !http://bitlgs.altervista.org/_altervista_ht/titolo_studio.png!
    why the second query doesn't use the bitmap index?
    problem #2:
    I create another bitmap index:
    CREATE BITMAP INDEX LSA.AAB_V_CLIENTE_SESSO_IDX ON LSA.AAB_VENDUTO(SESSO)
    FROM LSA.AAB_VENDUTO vv, LSA.AAB_CLIENTE cc WHERE vv.cliente_id=cc.cliente_id;and I run this query:
    SELECT VV.cliente_id, COUNT(*) FROM LSA.AAB_VENDUTO VV JOIN LSA.AAB_CLIENTE CC on VV.cliente_id=CC.cliente_id
    WHERE sesso='Donna' and (titolo_studio='LAUREA BREVE' or titolo_studio='MAGISTRALE') GROUP BY VV.cliente_id;this is the access plan:
    !http://bitlgs.altervista.org/_altervista_ht/terzo.png!
    In my opinion, the part that I have marked as 'A' is superfluous...
    why it make a join with AAB_CLIENTE table? Why it filter again the titolo_studio and sesso field?
    Edited by: Nirpol on 4-set-2009 13.25

    Nirpol wrote:
    I create 2 different bitmap join index:
    CREATE BITMAP INDEX lsa.AAB_V_ARTICOLO_MARCA_IDX ON LSA.AAB_VENDUTO(MARCA)
    FROM LSA.AAB_VENDUTO vv, LSA.AAB_ARTICOLO aa WHERE vv.articolo_id=aa.articolo_id;
    CREATE BITMAP INDEX lsa.AAB_V_CLIENTE_TIT_STUDIO_IDX ON LSA.AAB_VENDUTO(TITOLO_STUDIO)
    FROM LSA.AAB_VENDUTO vv, LSA.AAB_CLIENTE cc WHERE vv.cliente_id=cc.cliente_id;
    What happens if you just create two plain bitmap indexes without the join?
    CREATE BITMAP INDEX lsa.AAB_V_ARTICOLO_MARCA_IDX ON LSA.AAB_VENDUTO(MARCA);
    CREATE BITMAP INDEX lsa.AAB_V_CLIENTE_TIT_STUDIO_IDX ON LSA.AAB_VENDUTO(TITOLO_STUDIO) ;You can also go with normal indexes on the FK rows (cliente_id) and the optimizer can do a bitmap conversion from normal index to bitmap index if needed. Are the column values evenly distributed? If not you might need to go for some column histogram. but I don't have the impression that this is really useful in your case.

  • Problem with outer join/insert

    I created a test case in scott schema that describes my problem. I use emp table, and I want to have one more table - emp_info - that will store some additional info about employees. Not every employee will have additional info. I can't add a field to emp table - this has to be in an additional table.
    I want to display all the emp's in a swing table, and an info if it exists - of course, using outer join. Further more, I want users to be able to enter info in this same table. If info already exists in the emp_info it will be updated, if not a new record is created.
    I hope you get the picture.
    So, emp_info table is:
    create table emp_info(empno number(4), info varchar2(10))
    ALTER TABLE "SCOTT"."EMP_INFO"
    ADD (CONSTRAINT "PK_EMP_INFO" PRIMARY KEY("EMPNO"))
    ALTER TABLE "SCOTT"."EMP_INFO"
    ADD (CONSTRAINT "FK_EMP_INFO_EMP" FOREIGN KEY("EMPNO")
    REFERENCES "SCOTT"."EMP"("EMPNO"))
    In Jdev I create entitiy objects for emp and emp_info, and create View object 'ViewOuter' using these two entities. emp is updatable and empinfo is updatable and reference.
    SQL query for the view object is:
    SELECT Emp.EMPNO, Emp.ENAME, Emp.JOB, Emp.MGR, Emp.HIREDATE,
    Emp.SAL, Emp.COMM, Emp.DEPTNO, EmpInfo.EMPNO AS EMPNO1,
    EmpInfo.INFO
    FROM EMP Emp, EMP_INFO EmpInfo
    WHERE Emp.EMPNO = EmpInfo.EMPNO(+)
    I changed View row class of the ViewOuter view:
    public void setInfo(String value) {
    if (getEmpno1()==null) {
    setEmpno1(getEmpno());
    setAttributeInternal(INFO, value);
    Now I create the table in swing. It works fine - if a user changes info, new record is created or existing updated etc. There is only one problem:
    If I change info on an employee, and then requery the view without commiting to the database, I don't see this info. If I try to change it, I get error
    (oracle.jbo.TooManyObjectsException) JBO-25013: Too many objects match the primary key oracle.jbo.Key[7499 ].
    It seams that the new info is cached, but requerying the view didn't pick it up. And when it creates new row for info PK is violated.
    How can I avoid this?

    I set up the primari key for emp_info like this:
    public void setInfo(String value) {
    if (getEmpno1()==null) {
    setEmpno1(getEmpno());
    setAttributeInternal(INFO, value);
    It's set when the user enters info.
    What is the difference between transaction.commit and transaction.postChanges?
    Posting changes looks like good temp solution. How can I change view object, so it calls postchanges before executing query? Since I can do requery on multiple places in application, this should be handled by the view itself.
    Is there any better way?

  • Problem with outer joins and the class indicator/discriminator

    Hello,
    I am having a problem defining a query in toplink (10.1.3.3).
    In the workbench, I have created a parent and 2 child descriptors. The parent is "AbstractValue", the children are "DefaultValue", classified by the discriminator 'DEF', and "OverrideValue", classified by 'OVR', both located in the same table.
    Another descriptor (containing a one-on-one mapping to both a "DefaultValue", and a "OverrideValue") needs to be queried for its 'value'.
    The way the query should act is: If an override value (row) exists, this one applies for that object. If an override doesn't exist, return the default value.
    The query then comes down to (as I have it now):
    builder.getAllowingNull("OverrideValue").getAllowingNull("value").ifNull(builder.get("DefaultValue").get("value")).equal(builder.getParameter(VALUE_PARAM));
    The problem is that toplink adds the distinction for the different kind of "values" in the where clause WITHOUT checking for null values e.g. it performs an outer join, but then still checks for the discriminator value thus
    ....t1.ovr_id = t2.id(+) AND t2.discriminator = 'OVR' AND ...
    instead of
    ... LEFT JOIN values t2 ON (t1.ovr_id = t2.id AND t2.discriminator = 'OVR') ...
    This leads to the behaviour that the query returns ONLY the objects that have override and default values.
    An overview of the queries (simplified)
    Toplink, at the moment, returns only results if both override and default values exists:
    SELECT t1.id
    t1.def_id,
    t1.ovr_id
    FROM values t2,
    parameter t1,
    values t0
    WHERE nvl(t2.value, t0.value) = 15 AND
    t1.ovr_id = t2.id(+) AND t2.discriminator = 'OVR' AND
    t1.def_id = t0.id AND t0.discriminator = 'DEF'
    Situation Wanted:
    SELECT t1.id
    t1.def_id,
    t1.ovr_id
    FROM parameter t1
    LEFT JOIN values t2 ON (t1.ovr_id = t2.id AND t2.discriminator = 'OVR')
    JOIN values t0 ON (t1.def_id = t0.id AND t0.discriminator = 'DEF')
    WHERE nvl(t2.value, t0.value) = 15
    Anyone know if there is some statement I am missing to allow an actual outer join on descriptors containing class indicators/discriminators? A possible rewrite?
    Thanks in advance,
    Rudy

    This is a bug in TopLink's outer join support for Oracle. Currently the outer join is put in the where clause, instead of the from clause, as we do on other platforms. You might be able to fix it by changing your OraclePlatform to return false for shouldPrintOuterJoinInWhereClause().
    Please log this bug on EclipseLink, or through Oracle technial support.
    There is a workaround using,
    descriptor.getInhertiancePolicy().setAlwaysUseOuterJoinForClassType(true);
    James : http://www.eclipselink.org

  • Performance problem with inner join

    Hi
    With this Query
    SELECT *
    FROM TABLE1
    INNER JOIN TABLE2
    ON TABLE1.Col1 = TABLE2.Col2 AND TABLE1.Col2 = TABLE2.Col2
    WHERE TABLE1.Col3 = 'AB' AND
    TABLE2.Col4 = 'ZZ';
    TABLE1 have 6,000,000 of records
    TABLE2 have 9,000,000 of records
    when I run this query the result take 30 secs
    If I change the Optimizer_mode for 'RULE'
    the result take 4 secs
    All statistics is ok
    Primary Key exists for TABLE1 and TABLE2 base-on Col1 and Col2
    And index on Table1.Col3,Table1.Col4
    somebody can help me ?

    Analyze tables compute statistics
    and analyze index compute statistics
    I join explain plan
    STATEMENT_ID TIMESTAMP REMARKS OPERATION OPTIONS OBJECT_NODE OBJECT_OWNER OBJECT_NAME OBJECT_INSTANCE OBJECT_TYPE OPTIMIZER SEARCH_COLUMNS ID PARENT_ID POSITION COST CARDINALITY BYTES
    OTHER_TAG PARTITION_START PARTITION_STOP PARTITION_ID OTHER DISTRIBUTION CPU_COST IO_COST TEMP_SPACE
    WithRule1 2004-01-19 16:28:43 SELECT STATEMENT RULE 0
    WithRule1 2004-01-19 16:28:43 SORT AGGREGATE 1 0 1
    WithRule1 2004-01-19 16:28:43 NESTED LOOPS 2 1 1
    WithRule1 2004-01-19 16:28:43 TABLE ACCESS BY INDEX ROWID MICRODEV T088_INSC 1 ANALYZED 3 2 1
    WithRule1 2004-01-19 16:28:43 INDEX RANGE SCAN MICRODEV IX4_T088_INSC NON-UNIQUE ANALYZED 2 4 3 1
    WithRule1 2004-01-19 16:28:43 TABLE ACCESS BY INDEX ROWID MICRODEV T090_CPOS_DEM 2 ANALYZED 5 2 2
    WithRule1 2004-01-19 16:28:43 INDEX UNIQUE SCAN MICRODEV PK_T090_CPOS_DEM UNIQUE ANALYZED 2 6 5 1
    7 rows selected.
    STATEMENT_ID TIMESTAMP REMARKS OPERATION OPTIONS OBJECT_NODE OBJECT_OWNER OBJECT_NAME OBJECT_INSTANCE OBJECT_TYPE OPTIMIZER SEARCH_COLUMNS ID PARENT_ID POSITION COST CARDINALITY BYTES
    OTHER_TAG PARTITION_START PARTITION_STOP PARTITION_ID OTHER DISTRIBUTION CPU_COST IO_COST TEMP_SPACE
    WithChoose1 2004-01-19 16:29:37 SELECT STATEMENT CHOOSE 0 21680 21680 1 40
    21680
    WithChoose1 2004-01-19 16:29:37 SORT AGGREGATE 1 0 1 1 40
    WithChoose1 2004-01-19 16:29:37 HASH JOIN 2 1 1 21680 59050 2362000
    21680 3875000
    WithChoose1 2004-01-19 16:29:37 TABLE ACCESS BY INDEX ROWID MICRODEV T088_INSC 1 ANALYZED 3 2 1 7031 96727 2708356
    7031
    WithChoose1 2004-01-19 16:29:37 INDEX RANGE SCAN MICRODEV IX4_T088_INSC NON-UNIQUE ANALYZED 2 4 3 1 232 96727
    232
    WithChoose1 2004-01-19 16:29:37 TABLE ACCESS FULL MICRODEV T090_CPOS_DEM 2 ANALYZED 5 2 2 11224 5662693 67952316
    11224
    6 rows selected.

  • Problems with Natural Account segment while creating new SOB

    Hello everybody,
    I am testing a new GL SOB implementation in our test Instance. Below are the steps I followed.
    1)Created a new calender with 12 periods.
    2)Enabled Curriencies.
    3)Created a New AFF Structure with 4 segments.
    5)Created Value sets for those 4 segments and.
    6)Assigned Value sets to the Segments.
    7)Created LOV for the Value sets for the segments.
    8)Assigned Flexfield Qualifiers for the segments.
    segment1-Balance, SEG2-Natural Account, SEG3-Cost Center Accout &SEG-4 NO qualifier.
    9)Saved, Froze and Compiled the AFF Structure.
    10)Navigated to SETUP, FINANCIALS, BOOKS & DEFINE to create a new SOB.
    11)After entering all the details including Calender, COA, Currencies in the Closing Tab when entering the Account details for Retained Earnings, the AFF takes all the values for all the segments except for segment-2 which has been qualified as a Natural segment.
    12) I repeated the process by creating a new COA and it wont take the segment values which has been qualified as Natural Account. It gives me an error saying that No Entries Found For List Of Values and I double checked the Value List and Values and they are there.
    What am I doing wrong? I badly need some input here.
    Thank you.

    Hi
    1. How many values you have defined in Natural Account Segment Values.
    2. Could you please check while defining the Values there is check box called
    enabled. Have to checked it. Normally it is checked by default.
    Regards

  • Problem with outer join

    Tables
    Normal EMP TABLE and dept TABLE
    query
    SELECT e.deptno,d.dname
    FROM emp e , dept d
    WHERE E.DEPTNO(+)=D.DEPTNO
    AND (e.deptno=20 or e.job='CLERK')
    question
    When i use the above query i cannot get the extra records from dept table( 40 , OPERATIONS) due to a condition
    as long as it is "OR" we cannot use outer joins.
    Regardless of that condition i need to get that record(40,OPERATION)
    Please reply me it is very urgent for my work now..
    regards
    Boopathi

    select e.deptno,d.dname
    FROM emp e , dept d
    WHERE E.DEPTNO(+)=D.DEPTNO
    AND (e.deptno=20 or e.job='CLERK')
    This will only fetch the record for 20, IF you want for deptno 40 then you should remove your AND clause (AND (e.deptno=20 or e.job='CLERK'))
    select * from dept
    ===========
    DNAME     DEPTNO
    OPERATION     20
    FINANCE     40
    TRADE     22
    select * from emp
    ===========
    ENAME     DEPTNO     JOB
    a     20     CLERK
    b     22     XXX
    select e.deptno,d.dname
    FROM emp e , dept d
    WHERE e.DEPTNO(+)=d.DEPTNO
    =======================
    DEPTNO     DNAME
    20     OPERATION
    22     TRADE
         FINANCE--- This is the one which does not ahve a record in emp but is there in dept hence it has been returned

  • Problem with nature live theme

    Hi i downloaded the nature live theme on my curve 8520 it does appear on the theme page can you help

    Hello Chrisc
    you downloaded a theme & its appear on theme page, seems not an issue.
    I am assuming as it's not appearing on theme page.
    Please go in ownlaod folder, there you may found the icon of theme, you ay click on that to activate or check whether it is downloaded or not.
    please delete it and re-installing it may also help you.
    Thanks..!!

  • IN A NATURAL JOIN THE ANSWER QUERY DEPENDS OF PROJECTION ??!!

    Hi,
    Related to this question
    Link: problems with natural join
    Does the answer query depend of projection in a complex NATURAL JOIN query?
    Thanks,
    Ion

    You are most likely encountering this bug:
    Bug 5031632 - Wrong results from NATURAL JOIN, Metalink Note: 5031632.8
    It currently affects all versions of Oracle.
    You can tell something weird is going on by the EXPLAIN PLAN results:
    Query:
    SELECT     *
    FROM     BOOK
    NATURAL JOIN
         AUTHORSHIP
         NATURAL JOIN
              AUTHOR
              NATURAL JOIN
              COUNTRY
    WHERE     COUNTRY.NAMECOUNTRY = 'Canada'
    Explain Plan:
    SQL> /
    PLAN_TABLE_OUTPUT
    Plan hash value: 3878360587
    | Id  | Operation        | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT |      |     1 |    39 |    28   (8)| 00:00:01 |
    |*  1 |  HASH JOIN       |      |     1 |    39 |    28   (8)| 00:00:01 |
    |*  2 |   HASH JOIN      |      |     1 |    29 |    17   (6)| 00:00:01 |
    |*  3 |    HASH JOIN     |      |     1 |    23 |     9  (12)| 00:00:01 |
    |   4 |     VIEW         |      |     2 |    16 |     2   (0)| 00:00:01 |
    |   5 |      UNION-ALL   |      |       |       |            |          |
    |   6 |       FAST DUAL  |      |     1 |       |     2   (0)| 00:00:01 |
    |*  7 |       FILTER     |      |       |       |            |          |
    |   8 |        FAST DUAL |      |     1 |       |     2   (0)| 00:00:01 |
    |   9 |     VIEW         |      |     3 |    45 |     6   (0)| 00:00:01 |
    |  10 |      UNION-ALL   |      |       |       |            |          |
    |  11 |       FAST DUAL  |      |     1 |       |     2   (0)| 00:00:01 |
    |  12 |       FAST DUAL  |      |     1 |       |     2   (0)| 00:00:01 |
    |  13 |       FAST DUAL  |      |     1 |       |     2   (0)| 00:00:01 |
    |  14 |    VIEW          |      |     4 |    24 |     8   (0)| 00:00:01 |
    |  15 |     UNION-ALL    |      |       |       |            |          |
    |  16 |      FAST DUAL   |      |     1 |       |     2   (0)| 00:00:01 |
    |  17 |      FAST DUAL   |      |     1 |       |     2   (0)| 00:00:01 |
    |  18 |      FAST DUAL   |      |     1 |       |     2   (0)| 00:00:01 |
    |  19 |      FAST DUAL   |      |     1 |       |     2   (0)| 00:00:01 |
    |  20 |   VIEW           |      |     5 |    50 |    10   (0)| 00:00:01 |
    |  21 |    UNION-ALL     |      |       |       |            |          |
    |  22 |     FAST DUAL    |      |     1 |       |     2   (0)| 00:00:01 |
    |  23 |     FAST DUAL    |      |     1 |       |     2   (0)| 00:00:01 |
    |  24 |     FAST DUAL    |      |     1 |       |     2   (0)| 00:00:01 |
    |  25 |     FAST DUAL    |      |     1 |       |     2   (0)| 00:00:01 |
    |  26 |     FAST DUAL    |      |     1 |       |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - access("BOOK"."IDBOOK"="AUTHORSHIP"."IDBOOK")
       2 - access("AUTHORSHIP"."IDAUTHOR"="AUTHOR"."IDAUTHOR")
       3 - access("AUTHOR"."IDCOUNTRY"="COUNTRY"."IDCOUNTRY")
       7 - filter(NULL IS NOT NULL)
    Query:
    SELECT     NAMEBOOK
    FROM     BOOK
    NATURAL JOIN
         AUTHORSHIP
         NATURAL JOIN
              AUTHOR
              NATURAL JOIN
              COUNTRY
    WHERE     COUNTRY.NAMECOUNTRY = 'Canada'
    Explain Plan:
    SQL> /
    PLAN_TABLE_OUTPUT
    Plan hash value: 3246924444
    | Id  | Operation             | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT      |      |     1 |    24 |    27   (4)| 00:00:01 |
    |*  1 |  HASH JOIN            |      |     1 |    24 |    27   (4)| 00:00:01 |
    |   2 |   MERGE JOIN CARTESIAN|      |     1 |    21 |    19   (6)| 00:00:01 |
    |*  3 |    HASH JOIN          |      |     1 |    11 |     9  (12)| 00:00:01 |
    |   4 |     VIEW              |      |     2 |    16 |     2   (0)| 00:00:01 |
    |   5 |      UNION-ALL        |      |       |       |            |          |
    |   6 |       FAST DUAL       |      |     1 |       |     2   (0)| 00:00:01 |
    |*  7 |       FILTER          |      |       |       |            |          |
    |   8 |        FAST DUAL      |      |     1 |       |     2   (0)| 00:00:01 |
    |   9 |     VIEW              |      |     3 |     9 |     6   (0)| 00:00:01 |
    |  10 |      UNION-ALL        |      |       |       |            |          |
    |  11 |       FAST DUAL       |      |     1 |       |     2   (0)| 00:00:01 |
    |  12 |       FAST DUAL       |      |     1 |       |     2   (0)| 00:00:01 |
    |  13 |       FAST DUAL       |      |     1 |       |     2   (0)| 00:00:01 |
    |  14 |    BUFFER SORT        |      |     5 |    50 |    19   (6)| 00:00:01 |
    |  15 |     VIEW              |      |     5 |    50 |    10   (0)| 00:00:01 |
    |  16 |      UNION-ALL        |      |       |       |            |          |
    |  17 |       FAST DUAL       |      |     1 |       |     2   (0)| 00:00:01 |
    |  18 |       FAST DUAL       |      |     1 |       |     2   (0)| 00:00:01 |
    |  19 |       FAST DUAL       |      |     1 |       |     2   (0)| 00:00:01 |
    |  20 |       FAST DUAL       |      |     1 |       |     2   (0)| 00:00:01 |
    |  21 |       FAST DUAL       |      |     1 |       |     2   (0)| 00:00:01 |
    |  22 |   VIEW                |      |     4 |    12 |     8   (0)| 00:00:01 |
    |  23 |    UNION-ALL          |      |       |       |            |          |
    |  24 |     FAST DUAL         |      |     1 |       |     2   (0)| 00:00:01 |
    |  25 |     FAST DUAL         |      |     1 |       |     2   (0)| 00:00:01 |
    |  26 |     FAST DUAL         |      |     1 |       |     2   (0)| 00:00:01 |
    |  27 |     FAST DUAL         |      |     1 |       |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - access("BOOK"."IDBOOK"="AUTHORSHIP"."IDBOOK")
       3 - access("AUTHOR"."IDCOUNTRY"="COUNTRY"."IDCOUNTRY")
       7 - filter(NULL IS NOT NULL)
    41 rows selected.There are two major differences in these plans.
    1. The correct result has HASH JOINS. However the incorrect result has a MERGE JOIN CARTESIAN. A cartesian join should not be here as there is no need for one per the table structure and NATURAL JOIN syntax.
    2. There is a filter condition missing in the predicate information session.
    Both #1 and #2 above point to the bug I identified. The current work around us to use the JOIN ... ON syntax.
    HTH!

  • 3 tables with left joins - bug?

    Hello,
    i am making query where i encounter problem with left join in oracle. I am using oracle 10g and i prepare simple test case.
    he is testing tables and datas - really simple i think:
    drop table t1;
    drop table t2;
    drop table t3;
    create table t1 (a number not null);
    create table t2 (a number, b number);
    create table t3 (b number);
    insert into t3 values (1);
    insert into t3 values (2);
    insert into t3 values (3);
    insert into t1 (a) values (1);
    insert into t2 (a,b) values (1,1);
    insert into t1 (a) values (2);
    insert into t2 (a,b) values (2, null);
    insert into t1 (a) values (3);
    insert into t1 (a) values (4);
    insert into t2 (a,b) values (4,1);
    insert into t1 (a) values (5);
    insert into t2 (a,b) values (5,3);
    and now query with left joins:
    select
    t1.a
    , t2.a, t2.b
    , t3.b
    from
    t1, t2, t3
    where
    t1.a = t2.a (+)
    and t2.b = t3.b (+)
    and t3.b is null
    order by t1.a
    i get two rows as result:
    A A_1 B B_1
    2 2 null null      
    3 null null null                
    i expect these rows but when i change my query - i dont want get back t3.b column:
    select
    t1.a
    , t2.a, t2.b
    /* , t3.b*/
    from
    t1, t2, t3
    where
    t1.a = t2.a (+)
    and t2.b = t3.b (+)
    and t3.b is null
    order by t1.a
    i get only one row
    A A_1 B
    2 2 null
    My question is simple how can i only by changing columns getting back change number of returned rows? I must say i dont expect these result i expect two rows again.
    Thanks for help.

    BluShadow wrote:
    I think I know what you are getting at.
    By testing for null on t3.b when you aren't selecting the column, you are enforcing oracle to perform the join through t2 onto t1, but Oracle can't join because t2 has no matching row (although it's outer joined to t1) and therefore, for the one row it can't actually determine if t3.b is null or not, so that row can't match the conditions in a "true" sense and be displayed. If you select the column then oracle can test its nullness ok. (Perhaps this is a bug, I don't know, it's just how I know it works)If you get different results only by changing the projection part of the query this is a bug and nothing else. I can't reproduce using Oracle 10g XE, I get in both cases shown the expected two rows.
    What versions are you using to test this?
    SQL>
    SQL> select * from v$version
      2  where rownum <= 1;
    BANNER
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
    SQL>
    SQL> drop table t1 purge;
    Table dropped.
    SQL> drop table t2 purge;
    Table dropped.
    SQL> drop table t3 purge;
    Table dropped.
    SQL>
    SQL> create table t1 (a number not null);
    Table created.
    SQL> create table t2 (a number, b number);
    Table created.
    SQL> create table t3 (b number);
    Table created.
    SQL>
    SQL> insert into t3 values (1);
    1 row created.
    SQL> insert into t3 values (2);
    1 row created.
    SQL> insert into t3 values (3);
    1 row created.
    SQL>
    SQL> insert into t1 (a) values (1);
    1 row created.
    SQL> insert into t2 (a,b) values (1,1);
    1 row created.
    SQL>
    SQL> insert into t1 (a) values (2);
    1 row created.
    SQL> insert into t2 (a,b) values (2, null);
    1 row created.
    SQL>
    SQL> insert into t1 (a) values (3);
    1 row created.
    SQL>
    SQL> insert into t1 (a) values (4);
    1 row created.
    SQL> insert into t2 (a,b) values (4,1);
    1 row created.
    SQL>
    SQL> insert into t1 (a) values (5);
    1 row created.
    SQL> insert into t2 (a,b) values (5,3);
    1 row created.
    SQL>
    SQL> commit;
    Commit complete.
    SQL>
    SQL> select t1.a
      2       , t2.a, t2.b
      3       , t3.b
      4  from
      5         t1 left outer join t2 on (t1.a = t2.a)
      6            left outer join t3 on (t2.b = t3.b)
      7  where t3.b is null
      8  order by t1.a;
             A          A          B          B
             2          2
             3
    SQL>
    SQL> select t1.a
      2       , t2.a, t2.b
      3  --     , t3.b
      4  from
      5         t1 left outer join t2 on (t1.a = t2.a)
      6            left outer join t3 on (t2.b = t3.b)
      7  where t3.b is null
      8  order by t1.a;
             A          A          B
             2          2
             3
    SQL>Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Natural Join multiple tables bug!! SQLPLus 10.1.0.4.2

    SQLPLus 10.1.0.4.2 bug detected!! Who knows how to fix it? Many thanks
    I'm experimenting with natural join and found some really strange behaviour when I tried to combine multiple natural joins.
    I have the following schema:
    Model (ModelID PK, brand, type, year), 49 records
    Car (CarID PK, ModelID FK, OwnerID FK, price) 60 records
    Owner (OwnerID PK, name, adres) 48 records
    The database system is Oracle 10g 64bit on Windows 2003 64bit
    The following query gives me the result I expect (29 records):
    SELECT * FROM Owner NATURAL JOIN Car NATURAL JOIN Model
    WHERE brand='Volkswagen'
    However when I start specifying columns in the select clause the number of records in the result differs depending on the columns I select:
    SELECT OwnerID FROM Owner NATURAL JOIN Car NATURAL JOIN Model
    WHERE brand='Volkswagen'
    --> 1260 records
    SELECT OwnerID, CarID FROM Owner NATURAL JOIN Car NATURAL JOIN Model WHERE brand='Volkswagen'
    --> 1260 records
    SELECT ModelID FROM Owner NATURAL JOIN Car NATURAL JOIN Model
    WHERE brand='Volkswagen'
    --> 29 records (as expected).
    Would this be caused by a bug in Oracle or is there a logical explanation?
    TIA,
    Axel Hallez

    Duplicate thread:
    Natural Join bug!! Is this a sqlplus bug, how to fix it?

Maybe you are looking for

  • Itunes -50 error-any suggestions?

    I tried to rent a movie, and was given this error message in Itunes. 

  • I am unable to activate my copy of Adobe Acrobat 9 Pro

    I need assistance installing/activating the copy of Adobe Acrobat 9 Pro that came with my copy of Creative Suite 5 Web Premium.  I tried to use the key for CS5 and my volume license key for Acrobat 9 Pro to no avail.  I have a couple license keys wri

  • How do I multiply an image and animate it in 3d space to create a shape?

    My boss has a small clip he would like me to make. He wants me to take an image (Its just a square image) and have it start in the center of the screen, and as it scales down and moves to one of the bottom corners (I've already got that part done) th

  • File download/code

    Hello, I'm using JDeveloper 11.1.1.3. I'm trying to read the value of an attribute in an "ADF Quick Query with Table" called "Filename" and compare it with list of files i have in the directory "C:\\demos". Once the value is matched, the file with th

  • PDF Link properties \ Actions my URLs change

    When I upload a pdf file, "that contains hyperlinks to network files", to our internal sharepoint server, the links change. They go from "\\server location" to "http://server name". Is there a setting I can check off to stop this from happening?