Foreign key queries

Hi
I have 2 tables as below
Item_Master
- item_id
- item_name
- item_rate
Item_Group (can contain only 2 items in a group)
- group_id
- item_id1
- item_id2
now for a report on item_group i have written the following query but that does not work
select a.group_id, a.item_id1||' - '||b.item_name, a.item_id2||' - '||b.item_name
from item_group a, item_master b
where a.item_id1 = b.item_id and a.item_id1 = b.item_id
i dont understand whats the problem
Thanks

If you have two foreign keys, you need two joins:
select a.group_id, a.item_id1||' - '||b1.item_name, a.item_id2||' - '||b2.item_name
from item_group a, item_master b1, item_master b2
where a.item_id1 = b1.item_id
and a.item_id2 = b2.item_id

Similar Messages

  • Unable to create foreign key: InvalidArgument=Value of '0' is not valid for 'index'. Parameter name: index

    I am running an SQL(CE) script to create a DB. All script commands succeed, but the DB get "broken" after creating the last costaint: after running the script, viewing table properties of Table2 and clicking on "Manage relations" gives the following error: Unable to create foreign key: InvalidArgument=Value of '0' is not valid for 'index'. Parameter name: index. Wondering what does that refer to...
    Here it is the script. Please note that no error is thrown by running the following queries (even from code that passing the queries by hand, one-by-one to sql server management studio).
    CREATE TABLE [table1] (
    [id_rubrica] numeric(18,0) NOT NULL
    , [id_campo] numeric(18,0) NOT NULL
    , [nome] nvarchar(100) NOT NULL
    GO
    ALTER TABLE [table1] ADD PRIMARY KEY ([id_rubrica],[id_campo]);
    GO
    CREATE UNIQUE INDEX [UQ__m_campi] ON [table1] ([id_campo] Asc);
    GO
    CREATE TABLE [table2] (
    [id_campo] numeric(18,0) NOT NULL
    , [valore] nvarchar(4000) NOT NULL
    GO
    ALTER TABLE [table2] ADD PRIMARY KEY ([id_campo],[valore]);
    GO
    ALTER TABLE [table2] ADD CONSTRAINT [campo_valoriFissi] FOREIGN KEY ([id_campo]) REFERENCES [table1]([id_campo]);
    GO
    Sid (MCP - http://www.sugata.eu)

    I know this is kind of old post, but did this realy solved your problem?
    I'm getting this same error message after adding a FK constraint via UI on VS2008 Server Explorer.
    I can add the constraint with no errors, but the constraint is not created on the DataSet wizard (strongly typed datasets on Win CE 6) and when I click "Manage Relations" on the "Table Properties" this error pop out:
    "InvalidArgument=Value or '0' is not valid for 'index'.
    Parameter name: index"
    Even after vreating my table with the relation in SQL the same occurs:
    CREATE TABLE pedidosRastreios (
        idPedidoRastreio INT NOT NULL IDENTITY PRIMARY KEY,
        idPedido INT NOT NULL CONSTRAINT FK_pedidosRastreios_pedidos REFERENCES pedidos(idPedido) ON DELETE CASCADE,
        codigo NVARCHAR(20) NOT NULL

  • Query Builder - foreign key relationships not showing automatically

    Is it standard functionality in APEX that foreign key to primary key relationships are not shown in Query Builder when choosing related tables? Do you always have to join FKs to PKs manually (i.e. using control click) whenever you create joins in queries? In Oracle forms and SQL Developer the foreign key constaints are always draw in automatically. Any reason why this is not part of APEX's query builder as well? It's such a hassel to have to put them in each time when the relationships could easily be read directly from the data dictionary constraints.
    regards
    Paul P

    bump...

  • Foreign keys in SCD2 dimensions and fact tables in data warehouse

    Hello.
    I have datawarehouse in snowflake schema. All dimensions are SCD2, the columns are like that:
    ID (PK) SID NAME ... START_DATE END_DATE IS_ACTUAL
    1 1 XXX 01.01.2000 01.01.2002 0
    2 1 YYX 02.01.2002 01.01.2004 1
    3 2 SYX 02.01.2002 1
    4 3 AYX 02.01.2002 01.01.2004 0
    5 3 YYZ 02.01.2004 1
    On this table there are relations from other dimension and fact table.
    Need I create foreign keys for relation?
    And if I do, on what columns? SID (serial ID) is not unique. If I create on ID, I have to get SID and actual row in any query.

    >
    I have datawarehouse in snowflake schema. All dimensions are SCD2, the columns are like that:
    ID (PK) SID NAME ... START_DATE END_DATE IS_ACTUAL
    1 1 XXX 01.01.2000 01.01.2002 0
    2 1 YYX 02.01.2002 01.01.2004 1
    3 2 SYX 02.01.2002 1
    4 3 AYX 02.01.2002 01.01.2004 0
    5 3 YYZ 02.01.2004 1
    On this table there are relations from other dimension and fact table.
    Need I create foreign keys for relation?
    >
    Are you still designing your system? Why did you choose NOT to use a Star schema? Star schema's are simpler and have some performance benefits over snowflakes. Although there may be some data redundancy that is usually not an issue for data warehouse systems since any DML is usually well-managed and normalization is often sacrificed for better performance.
    Only YOU can determine what foreign keys you need. Generally you will create foreign keys between any child table and its parent table and those need to be created on a primary key or unique key value.
    >
    And if I do, on what columns? SID (serial ID) is not unique. If I create on ID, I have to get SID and actual row in any query.
    >
    I have no idea what that means. There isn't any way to tell from just the DDL for one dimension table that you provided.
    It is not clear if you are saying that your fact table will have a direct relationship to the star-flake dimension tables or only link to them through the top-level dimensions.
    Some types of snowflakes do nothing more than normalize a dimension table to eliminate redundancy. For those types the dimension table is, in a sense, a 'mini' fact table and the other normalized tables become its children. The fact table only has a relation to the main dimension table; any data needed from the dimensions 'child' tables is obtained by joining them to their 'parent'.
    Other snowflake types have the main fact table having relations to one or more of the dimensions 'child' tables. That complicates the maintenance of the fact table since any change to the dimension 'child' table impacts the fact table also. It is not recommended to use that type of snowflake.
    See the 'Snowflake Schemas' section of the Data Warehousing Guide
    http://docs.oracle.com/cd/B28359_01/server.111/b28313/schemas.htm
    >
    Snowflake Schemas
    The snowflake schema is a more complex data warehouse model than a star schema, and is a type of star schema. It is called a snowflake schema because the diagram of the schema resembles a snowflake.
    Snowflake schemas normalize dimensions to eliminate redundancy. That is, the dimension data has been grouped into multiple tables instead of one large table. For example, a product dimension table in a star schema might be normalized into a products table, a product_category table, and a product_manufacturer table in a snowflake schema. While this saves space, it increases the number of dimension tables and requires more foreign key joins. The result is more complex queries and reduced query performance. Figure 19-3 presents a graphical representation of a snowflake schema.

  • Accurate statistics on skewed foreign key when coming from parent

    Hi,
    I will be as short as possible:
    - we have two tables in a parent - child relationship. The foreign key is very skewed and we need to get child details coming from the parent
    - CBO is not considering the skeweness from histograms on foreign key column (I suppose it cannot as it is the example without going into tables) and it calculates the expected returning rows in the execution plan as no_rows / distinct_values => 10,000 / 3 = 3,333 rows for both execution plans, even if they returns effectively 1 row / 9,999 rows. In histograms exists this information but it cannot be extracted by CBO as it is.
    Any idea how to help CBO to choose separate execution plans for query 1 and query 2 excluding hints or query modifications?
    -- Oracle Database 10.2.0.3
    --DROP TABLE child;
    --DROP TABLE parent;
    CREATE TABLE parent AS SELECT LEVEL parent_num, 'parent_' || LEVEL parent_id FROM DUAL CONNECT BY LEVEL <= 10;
    ALTER TABLE parent ADD CONSTRAINT parent_pk PRIMARY KEY (parent_num);
    CREATE UNIQUE INDEX parent_id_ix ON PARENT (parent_id, parent_num);
    CREATE TABLE child AS SELECT DECODE (LEVEL, 1, 1, 10000, 10, 5) parent_num, 'child_' || LEVEL child_id FROM DUAL CONNECT BY LEVEL <= 10000;
    ALTER TABLE child ADD FOREIGN KEY (parent_num) REFERENCES parent (parent_num) ON DELETE CASCADE;
    CREATE INDEX child_parent_num_ix ON CHILD(parent_num);
    exec dbms_stats.gather_table_stats(ownname=>'***REPLACE WITH YOUR OWN USER***',tabname=>'PARENT',estimate_percent=>100,cascade=>TRUE,method_opt=>'FOR ALL COLUMNS SIZE 1');
    exec dbms_stats.gather_table_stats(ownname=>'***REPLACE WITH YOUR OWN USER***',tabname=>'CHILD',estimate_percent=>100,cascade=>TRUE,method_opt=>'FOR COLUMNS parent_num SIZE 3, child_id SIZE 1');
    -- QUERY 1: this query should be very selective (1 row), using index
    SELECT c.child_id FROM child c, parent p WHERE c.parent_num = p.parent_num AND p.parent_id = 'parent_1';
    -- QUERY 2: it should return 99.9999% of the rows (9,999 rows), so it should use full table scan
    SELECT c.child_id FROM child c, parent p WHERE c.parent_num = p.parent_num AND p.parent_id = 'parent_5';
    In reality both queries have the same execution plan as below:
    Execution Plan
    Plan hash value: 4033709836
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 3333 | 83325 | 6 (0)| 00:00:01 |
    | 1 | NESTED LOOPS | | 3333 | 83325 | 6 (0)| 00:00:01 |
    | 2 | TABLE ACCESS BY INDEX ROWID| PARENT | 1 | 12 | 1 (0)| 00:00:01 |
    |* 3 | INDEX UNIQUE SCAN | PARENT_ID_IX | 1 | | 0 (0)| 00:00:01 |
    |* 4 | TABLE ACCESS FULL | CHILD | 3333 | 43329 | 5 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    3 - access("P"."PARENT_ID"='parent_1')
    4 - filter("C"."PARENT_NUM"="P"."PARENT_NUM")
    Execution Plan
    Plan hash value: 4033709836
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 3333 | 83325 | 6 (0)| 00:00:01 |
    | 1 | NESTED LOOPS | | 3333 | 83325 | 6 (0)| 00:00:01 |
    | 2 | TABLE ACCESS BY INDEX ROWID| PARENT | 1 | 12 | 1 (0)| 00:00:01 |
    |* 3 | INDEX UNIQUE SCAN | PARENT_ID_IX | 1 | | 0 (0)| 00:00:01 |
    |* 4 | TABLE ACCESS FULL | CHILD | 3333 | 43329 | 5 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    3 - access("P"."PARENT_ID"='parent_5')
    4 - filter("C"."PARENT_NUM"="P"."PARENT_NUM")
    column table_name format A10
    column column_name format A11
    column endpoint_actual_value format A21
    select * from user_tab_histograms where table_name='CHILD' and column_name='PARENT_NUM';
    TABLE_NAME COLUMN_NAME ENDPOINT_NUMBER ENDPOINT_VALUE ENDPOINT_ACTUAL_VALUE
    CHILD PARENT_NUM 1 1
    CHILD PARENT_NUM 9999 5
    CHILD PARENT_NUM 10000 10
    3 rows selected.
    I am sorry about the formatting but this is the best I could following plain text help.
    Thank you,
    Eugen
    Edited by: Eugen Iacob on Dec 13, 2011 3:21 AM
    Edited by: Eugen Iacob on Dec 13, 2011 12:36 PM
    Edited by: Eugen Iacob on Dec 13, 2011 12:37 PM
    Edited by: Eugen Iacob on Dec 14, 2011 2:13 AM

    Hi,
    you can create a function based index on child table, and query that value instead of parent_id from parent table.
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
    PL/SQL Release 10.2.0.1.0 - Production
    CORE     10.2.0.1.0     Production
    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    CREATE TABLE parent AS SELECT LEVEL parent_num, 'parent_' || LEVEL parent_id, 'some text ' || level parent_name
    FROM DUAL CONNECT BY LEVEL <= 10;
    ALTER TABLE parent ADD CONSTRAINT parent_pk PRIMARY KEY (parent_num);
    CREATE UNIQUE INDEX parent_id_ix ON PARENT (parent_id, parent_num);
    CREATE TABLE child AS SELECT DECODE (LEVEL, 1, 1, 10000, 10, 5) parent_num, 'child_' || LEVEL child_id,
    'some text ' || level child_name
    FROM DUAL CONNECT BY LEVEL <= 10000;
    ALTER TABLE child ADD FOREIGN KEY (parent_num) REFERENCES parent (parent_num) ON DELETE CASCADE;
    CREATE INDEX child_parent_num_ix ON CHILD(parent_num);
    CREATE OR REPLACE function get_parent_id( in_parent_num in number )
    RETURN parent.parent_id%TYPE
    DETERMINISTIC
    IS
      ret parent.parent_id%TYPE;
    BEGIN
      SELECT parent_id INTO ret
      FROM parent
      WHERE parent_num = in_parent_num;
      RETURN ret;
    END;
    CREATE INDEX child_parent_id_idx ON child( get_parent_id( parent_num ) );
    exec dbms_stats.gather_table_stats(ownname=>user,tabname=>'CHILD',estimate_percent=>100,cascade=>TRUE,method_opt=>'FOR ALL HIDDEN COLUMNS');
    explain plan for
    SELECT p.parent_name, c.child_name
    FROM child c, parent p
    WHERE c.parent_num = p.parent_num AND get_parent_id(c.parent_num ) = 'parent_1';
    select * from table( dbms_xplan.display );
    plan FOR succeeded.
    PLAN_TABLE_OUTPUT                                                                                                                                                                                                                                                                                           
    Plan hash value: 3790918082                                                                                                                                                                                                                                                                                 
    | Id  | Operation                    | Name                | Rows  | Bytes | Cost (%CPU)| Time     |                                                                                                                                                                                                        
    |   0 | SELECT STATEMENT             |                     |     1 |    77 |     3   (0)| 00:00:01 |                                                                                                                                                                                                        
    |   1 |  NESTED LOOPS                |                     |     1 |    77 |     3   (0)| 00:00:01 |                                                                                                                                                                                                        
    |   2 |   TABLE ACCESS BY INDEX ROWID| CHILD               |     1 |    37 |     2   (0)| 00:00:01 |                                                                                                                                                                                                        
    |*  3 |    INDEX RANGE SCAN          | CHILD_PARENT_ID_IDX |     1 |       |     1   (0)| 00:00:01 |                                                                                                                                                                                                        
    |   4 |   TABLE ACCESS BY INDEX ROWID| PARENT              |     1 |    40 |     1   (0)| 00:00:01 |                                                                                                                                                                                                        
    |*  5 |    INDEX UNIQUE SCAN         | PARENT_PK           |     1 |       |     0   (0)| 00:00:01 |                                                                                                                                                                                                        
    Predicate Information (identified by operation id):                                                                                                                                                                                                                                                         
       3 - access("TEST"."GET_PARENT_ID"("PARENT_NUM")='parent_1')                                                                                                                                                                                                                                              
       5 - access("C"."PARENT_NUM"="P"."PARENT_NUM")                                                                                                                                                                                                                                                            
    Note                                                                                                                                                                                                                                                                                                        
       - dynamic sampling used for this statement                                                                                                                                                                                                                                                               
    22 rows selected
    explain plan for
    SELECT  p.parent_id, c.child_id
    FROM child c, parent p
    WHERE c.parent_num = p.parent_num AND get_parent_id(c.parent_num ) = 'parent_5';
    select * from table( dbms_xplan.display );
    plan FOR succeeded.
    PLAN_TABLE_OUTPUT                                                                                                                                                                                                                                                                                           
    Plan hash value: 2656363181                                                                                                                                                                                                                                                                                 
    | Id  | Operation          | Name         | Rows  | Bytes | Cost (%CPU)| Time     |                                                                                                                                                                                                                         
    |   0 | SELECT STATEMENT   |              |  9998 |   732K|    23  (27)| 00:00:01 |                                                                                                                                                                                                                         
    |*  1 |  HASH JOIN         |              |  9998 |   732K|    23  (27)| 00:00:01 |                                                                                                                                                                                                                         
    |   2 |   INDEX FULL SCAN  | PARENT_ID_IX |    10 |   380 |     1   (0)| 00:00:01 |                                                                                                                                                                                                                         
    |*  3 |   TABLE ACCESS FULL| CHILD        |  9998 |   361K|    21  (24)| 00:00:01 |                                                                                                                                                                                                                         
    Predicate Information (identified by operation id):                                                                                                                                                                                                                                                         
       1 - access("C"."PARENT_NUM"="P"."PARENT_NUM")                                                                                                                                                                                                                                                            
       3 - filter("GET_PARENT_ID"("C"."PARENT_NUM")='parent_5')                                                                                                                                                                                                                                                 
    Note                                                                                                                                                                                                                                                                                                        
       - dynamic sampling used for this statement                                                                                                                                                                                                                                                               
    20 rows selected

  • Hibernate: how to null out foreign key references when deleting an entity?

    We use Spring/Hibernate3 in our app, and ran into kind of a bummer of a problem. We have a relationship that is many-to-one (e.g. Student -> School). This is represented by a schoolId on the Student table. When we delete the school through the Hibernate layer, we are immediately receiving foreign key constraints because Hibernate does not null out the Students' schoolId columns where applicable.
    What we'd like to see happen is something like this:
    1. SchoolDAO.delete(id)
    Hibernate: UPDATE Student set schoolId = NULL where schoolId = ?
    Hibernate: DELETE from School where id = ?
    But what we're actually seeing is:
    1. SchoolDAO.delete(id)
    Hibernate: DELETE from School where id = ?
    And hence the foreign key constraints.
    Was wondering if someone else here has run into this. Someone on the Hibernate forums suggested using an Interceptor, but the Hibernate3 interceptors don't give us access to the Session to allow us to do a bulk update to null out these references. Apparently the interceptor javadoc says that the interceptor is basically there to change properties on the object in question and should not involve the session at all.
    We then looked at implementing an Event, and that worked, but was not called for every cascade deleted event. We have a lot of cascade activity in our database, so that was a little disappointing.
    We had briefly considered manually nulling out that FK in the DAO itself, but that would not work with the large amount of Hibernate driven cascade deletion that goes on in our app (Hibernate does not call our DAO every time it cascade deletes an entity).
    Would greatly appreciate any pointers on this subject. We're hoping that others have run into this as well.
    thanks.

    I'm not sure why you'd expect that given that there's
    not really an equivalent object oriented operation -
    if you want to relinquish the object in the OO scheme
    of things you have to null all the references to it;
    you can't just say "make everything that points to
    this object null".I can field that question. We came from EJB 2.x where in the event that you deleted a School entity bean using ejbRemove() you would see the following queries generated:
    UPDATE Student set schoolId = NULL where schoolId = ?
    DELETE from School where id = ?
    Basically, it would manage the relationship for you. I know it's a completely different system but we were a little surprised to learn that Hibernate did not do this on its own as well.

  • Necessary to have foreign keys ?

    Dear All,
    We have a oracle database, in which there is no foreign key constraints defined. But we are able to join the tables with the appropriate columns and getting the output of the query perfectly.
    Now, is that mandatory to have foreign key columns defined or the current design is fine. Please help me in this, by discussing the advantages and disadvantages.
    Thanks in advance.
    Anand.

    Best practice would absolutely be to have foreign keys in an OLTP system.
    Without foreign keys, you are guaranteed to have data that violates referential integrity eventually. Unless you happen to be lucky enough to work on an application that will never have bugs, you need Oracle to enforce referential integrity.
    Without foreign keys, your data model is much harder to understand. That means that when new developers come on the project, when people want to point various tools at the database, etc. those people and tools will not be able to use foreign keys to determine how the tables relate. That inevitably means that it will take them far longer to get up to speed and they are far more likely to make errors. If you ever point an automated tool at the database to generate an ERD, that tool will be nearly useless since it can't figure out how the tables relate.
    Without foreign keys, you're depriving the optimizer of information that may allow it to generate better plans.
    Yes, you need to index foreign keys in the child table, but you almost certainly need these indexes for queries anyway. Other than that, there are really no downsides. Yes, Oracle has to do a minute amount of work to verify the foreign key during DML, but it will be far more efficient for Oracle to do this than for your application to do it.
    Justin

  • Problem with Foreign Key relationships in SAP R/3 4.7

    Hi Experts,
    I am trying to create a foreign key relationship between 2 transparent tables in SAP R/3 4.7
    Table 1:ZAAVNDR (MANDT (pk), VENDORNO (pk), NAME, REGION, COUNTRY (fk)) Foreign Key Table
    Table 2: ZAAVNDRREF(MANDT(pk), COUNTRY (pk)) ---Check table
    I have added few valid countries in check table but when I am adding some records in foreign key table with invalid countries these records are not being restricted and are still successfully going into the table.
    Could any one please help in this.
    Thanks in anticipation.
    -Amit

    Hi Sandra,
    Many thanks for your response and providing time of yours.
    Now, I have done exactly the same thing, but still it is the same.
    I have created two new tables as below:
    ZAAVREF (Check table)
    MANDT (PK)
    COUNTRY (PK) Domain:ZAACOUNT (CHAR 10)
    ZAAV1 (Foreign key table)
    MANDT (PK)
    COUNTRY (PK) Domain:ZAACOUNT (CHAR 10)
    Then I have created FK on country of foreign key table ZAAV1 and then SE16 (for table ZAAVREF)->Create Entries-> Entered values for Country only->Save....Records entered with valid Country values.
    After that SE16 (for table ZAAV1)->Create Entries-->Entered an Invalid country->Save->Still the record entered to the Database successfully....
    Could you please let me know where I am going wrong.
    I am using SAP R/3 4.7 and creating tables using Tools->ABAP Workbench->Development->ABAP dictionary

  • Can not insert null into foreign key issue

    Hi ,
    I am having parent-child relationship table.
    In the child table when I am adding a new record , data is getting inserted with foreign key.
    After insert if I immediately update the same record. Its giving error that can not insert null into foreign key.
    If i click on rollback button I am able to update that record properly.

    Hi ,
    I am having parent-child relationship table.
    In the child table when I am adding a new record , data is getting inserted with foreign key.
    After insert if I immediately update the same record. Its giving error that can not insert null into foreign key.
    If i click on rollback button I am able to update that record properly.

  • ODI not able to detect primary/foreign keys from XML- user lacks privilege or object not found

    Hi Guys,
    Im trying to load an xml file with two entities address and employee as below. The topology reverse engineering everything works fine. Im even able to view the xml data  in ODI,  but when i try to load the data from these two entities joining by the schema primary keys and foreign keys which odi created on reverse engineering process for xml, im getting the below error.  Im able to load data from one entity, error only occurs when i use the join odi creates internally to identify the xml components employee and address
    XML File:
    <?xml version="1.0" encoding="UTF-8" ?>
    <EMP>
    <Empsch>
    <Employee>
    <EmployeeID>12345</EmployeeID>
    <Initials>t</Initials>
    <LastName>john</LastName>
    <FirstName>doe</FirstName>
    </Employee>
    <Address>
    <WorkPhone>12345</WorkPhone>
    <WorkAddress>Test 234</WorkAddress>
    </Address>
    </Empsch>
    </EMP>
    Topology:  jdbc:snps:xml?f=C:/Temp/RR/Empsch.xml&s=Empsch&re=EMP&dod=true&nobu=false
    Error Message:
    -5501 : 42501 : java.sql.SQLException: user lacks privilege or object not found: EMPSCH.EMPSCHPK
    java.sql.SQLException: user lacks privilege or object not found: EMPSCH.EMPSCHPK
        at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
        at org.hsqldb.jdbc.JDBCPreparedStatement.<init>(Unknown Source)
        at org.hsqldb.jdbc.JDBCConnection.prepareStatement(Unknown Source)
        at com.sunopsis.jdbc.driver.xml.SnpsXmlConnection.prepareStatement(SnpsXmlConnection.java:1232)
        at sun.reflect.GeneratedMethodAccessor65.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at oracle.odi.core.datasource.dwgobject.support.OnConnectOnDisconnectDataSourceAdapter$OnDisconnectCommandExecutionHandler.invoke(OnConnectOnDisconnectDataSourceAdapter.java:200)
        at $Proxy2.prepareStatement(Unknown Source)
        at oracle.odi.runtime.agent.execution.sql.SQLCommand.doInitializeStatement(SQLCommand.java:83)
        at oracle.odi.runtime.agent.execution.sql.SQLCommand.getStatement(SQLCommand.java:117)
        at oracle.odi.runtime.agent.execution.sql.SQLCommand.getStatement(SQLCommand.java:111)
        at oracle.odi.runtime.agent.execution.sql.SQLDataProvider.readData(SQLDataProvider.java:81)
        at oracle.odi.runtime.agent.execution.sql.SQLDataProvider.readData(SQLDataProvider.java:1)
        at oracle.odi.runtime.agent.execution.DataMovementTaskExecutionHandler.handleTask(DataMovementTaskExecutionHandler.java:70)
        at com.sunopsis.dwg.dbobj.SnpSessTaskSql.processTask(SnpSessTaskSql.java:2913)
        at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java:2625)
        at com.sunopsis.dwg.dbobj.SnpSessStep.treatAttachedTasks(SnpSessStep.java:577)
        at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java:468)
        at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java:2128)
        at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor$2.doAction(StartSessRequestProcessor.java:366)
        at oracle.odi.core.persistence.dwgobject.DwgObjectTemplate.execute(DwgObjectTemplate.java:216)
        at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.doProcessStartSessTask(StartSessRequestProcessor.java:300)
        at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.access$0(StartSessRequestProcessor.java:292)
        at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor$StartSessTask.doExecute(StartSessRequestProcessor.java:855)
        at oracle.odi.runtime.agent.processor.task.AgentTask.execute(AgentTask.java:126)
        at oracle.odi.runtime.agent.support.DefaultAgentTaskExecutor$2.run(DefaultAgentTaskExecutor.java:82)
        at java.lang.Thread.run(Thread.java:662)
    Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: EMPSCH.EMPSCHPK
        at org.hsqldb.error.Error.error(Unknown Source)
        at org.hsqldb.ExpressionColumn.checkColumnsResolved(Unknown Source)
        at org.hsqldb.QueryExpression.resolve(Unknown Source)
        at org.hsqldb.ParserDQL.compileCursorSpecification(Unknown Source)
        at org.hsqldb.ParserCommand.compilePart(Unknown Source)
        at org.hsqldb.ParserCommand.compileStatement(Unknown Source)
        at org.hsqldb.Session.compileStatement(Unknown Source)
        at org.hsqldb.StatementManager.compile(Unknown Source)
        at org.hsqldb.Session.execute(Unknown Source)
        ... 27 more
    Please advice
    Thanks
    Revanth

    Thats obvious from the xml file contents you have given here. In this xml file You have four complex type. Two of them are employee and address. However the employee doesnot have any relation with address as you have not added the relationship. Thats why its failing. Its not the fault of ODI.
    Also I would suggest not to use auto generated dtd by ODI as you might face problem in future. For example the address type of XML has 8 attributes and 4 of them are not mandatory. That means each of your xml file may have attributes between 4 to 8.  This is where ODI auto generated DTD fails.
    XML Schema complexType Element
    Thanks
    Bhabani

  • How to get multiple row data in single row for one value of foreign key

    i want to get data from a table in a way that all the emp_id corresponding to one manager_id
    in employee table come in one row. (emp_id is the primary key and manager_id is the foreign key) Since there are different emp_id whose manager_id is same
    so how can i get all the emp_id in one row .

    One way with 10g:
    select mgr,
           rtrim(xmlagg(xmlelement(empno,empno||',').extract('//text()')),',')  emps
    from emp
    where mgr is not null
    group by mgr;10g:
    -- define this function:
    create or replace
    function concatenate(c Sys_refcursor, sep varchar2 default null) return varchar2
    as
      val varchar2(100);
      return_value varchar2(4000);
    begin
    --  open c;
      loop
      fetch c into val;
      exit when c%notfound;
      if return_value is null then
        return_value:=val;
      else
        return_value:=return_value||sep||val;
      end if;
      end loop;
      return return_value;
    end;
    select mgr,
           concatenate(cursor(select empno from emp e where e.mgr=emp.mgr order by empno),',')
    from emp
    where mgr is not null
    group by mgr;With 11g:
    select mgr,
           listagg(empno,',') within group (order by empno) emps
    from emp
    where mgr is not null
    group by mgr;

  • Foreign key

    How can I insert a row into a table with the foreign key of column ID?
    The foreign key link to other unique key of other table.
    My code:
    Long id = 43850943l;
    PreparedStatement persInfUpdate = con.prepareStatement("INSERT INTO PersonalInfo (ID, FirstName, SecondName, Age, GenderMale, Married) VALUES (?, ?, ?, ?, ?, ?)");
    persInfUpdate.setLong(1, id);
    persInfUpdate.setString(2, personalInfo.getFirstName());
    persInfUpdate.setString(3, personalInfo.getLastName());
    persInfUpdate.setInt(4, personalInfo.getAge());
    persInfUpdate.setBoolean(5, personalInfo.isGenderMale());
    persInfUpdate.setBoolean(6, personalInfo.isMarried());
    persInfUpdate.executeUpdate();
    Error:
    INSERT on table 'PERSONALINFO' caused a violation of foreign key constraint 'F1_KEY' for key (0). The statement has been rolled back.

    The foreign key must already exist before you can do update.
    Jamie

  • Binding for table produces list for other tables using foreign key and crea

    Using
    software Jdev 11G, WLS 11G, Oracle DB 11G, Windows Vista platform
    technology EJB 3.0, jspx, backing beans, session bean
    I cannot create a namedquery on my secondary table. The method for the column uses the entity object rather than the name and value of the column.
    For instance,
    (Coketruck) table has inventory records(Products) table
    Coketruck has one to many to the Products table
    Products has a many to one to the Coketruck
    I need to return the products from the product table based on the CokeTruck but I cannot create a namedQuery because the method in the Product table is an entity object type instead of a long that I can use to look up all the products based off the column truck_id.
    This is what I was expecting…
    Private Long truckId;
    public Long getTruckId() {
    return truckId;
    public void setTruckId (Long truckId) {
    this. truckId = truckId;
    Instead this is what I have…
    @ManyToOne
    @JoinColumn(name = "TRUCK_ID")
    private Coketruck coketruck;
    this. coketruck = coketruck
    public Coketruck getCoketruck() {
    return coketruck;
    public void set Coketruck (Coketruck coketruck) {
    this. coketruck = coketruck;
    How do I do a query on the Product table to return all the products that are in the coketruck?
    If I do the following it expects for me to pass the Entity Object which I cannot use as search criteria for my find method.
    @NamedQuery(name = "Products.findById", query = "select o from Products o where o.truckId = :truckId")
    On a different note but the same song…
    I noticed that when I look at my Session Bean Data Contols that the coketruck already has a list of the products. I have created a jsp page with a backing bean and have been able to use the namedquery on the coketruck entity to retrieve the productList. Unfortunately I need to sort the products by type and was also not able to find where to perform the work to be able to iterate through the productList to get my desired display. Therefore I started looking at doing another namedquery that would only retrieve the product_type ordering by the truckId.
    Seems I have come full circle… I don’t care what method I have to use to get the info back.
    Any help is greatly appreciated!

    user9005175 wrote:
    Hi!
    I work on an application wich uses a shopping cart stored in a database. The shopping cart uses two tables:
    CART: Holds information common for one shopping cart: the user it is connected to etc.
    - Primary key: CART_ID
    CART_ROW: One row in the cart, e.g. one new product to buy.
    - Primary key: ROW_ID
    - Foreign key: CART_ROW.CART_ID references CART.CART_ID
    From the code the rows in the cart are collected per cart, as is modelled by the foreign key. There exists one more relationship, which we use in the code, but which is not modelled by a foreign key in the database. One row can be dependent on another row, which makes the other row a parent.
    CART_ROW has a column PARENT_ID which references CART_ROW.ROW_ID.
    Should we add a foreign key for PARENT_ID? Or are there any questions to consider when it is a foreign key to the same table?
    I suggest to add foreign key it wont harm the performance (except while on insert when there would be validation for the foreign key). But it would prevent users to insert wrong/corrupt data either through code or directly by loggin in the database.
    A while ago we added indexes, both on ROW_ID and on PARENT_ID. Could the index on PARENT_ID have been harmful, since there is no foreign key?
    Index on parent_id would only be harmful if you do not make use of index after creating it (i.e. there is no query which make use of this index).
    And if you decide to have a foreign key on parent_id then I suggest to have index too on parent_id as it would be helpful atleast when you delete any record in this table.
    Best regards!

  • Can we associate index with foreign key?

    hello
    i have searched and could not find the answer to the above;
    i have a foreign key constraint on the tables; i added an index on that column as well;
    however when i query the all_constraints, under index_name for this foreign constraint there is nothing; only when i have PK/UK i case see indexes associated with them;
    will then oracle still associate my index with the FK constrained column? or i need to excplicity associate it with the foreign key column? if so, how to do that?
    thx
    rgds

    Hi,
    UserMB wrote:
    i have a foreign key constraint on the tables; i added an index on that column as well;It helps if you give a specific example, such as:
    "I have a foreign key constraint, where emp.deptno references dept.deptno. (Deptno is the primary key of dept.) I created an index called emp_deptno_idx on emp.deptno as well."
    however when i query the all_constraints, under index_name for this foreign constraint there is nothing; only when i have PK/UK i case see indexes associated with them;Not all indexes are associated with a constraint. In the example above, you wouldn't expect to see anything about the index emp_demptno_idx in all_constraints or in all_cons_columns.
    will then oracle still associate my index with the FK constrained column? or i need to excplicity associate it with the foreign key column? if so, how to do that?In the situation above, Oracle will still use the index when the optimizer thinks it will help. You don't have to do anything else.

  • Subquery in IF statement in trigger, without using foreign keys

    Hello,
    I'm investigating ways of writing a subquery in an IF statement, which is placed inside a trigger.
    I wanna write smth like IF (:new.jazz not in (select goldies from T where ... )) etc. I don't know whether the fact that the IF is in a trigger adds some additional restrictions. (Does it?)
    So far I found the solution described here: SubQuery Comparison in If Statement which I find a bit tacky, I could have the 'cooleststarinthegalaxy' instead of 1 and seems you need to do extra light, but still extra lifting.
    I also read about the possibility of using MERGE, which I'm currently researching.
    Is there any other way?
    Thanks
    Edited by: BluShadow on 14-Nov-2012 13:37
    fixed link
    Edite by me: the question is how (if possible) to do this without a foreign key.
    Edited by: questioningq12 on Nov 14, 2012 6:11 AM
    Edited by: questioningq12 on Nov 14, 2012 6:13 AM

    Hi,
    questioningq12 wrote:
    Say I have tables A(namea varchar(10)), B(nameb varchar(10)), and B contains tuples ('1stname','2ndname').
    I wrote a trigger before insertion, for each row, on table A. For a tuple t to be inserted, it should check whether t.namea is in the set of values nameb from B.
    E.g., INSERT INTO A VALUES('1stname') should work. But INSERT INTO A VALUES ('3rdname') should fail. You can use a foreign key constraint for that.
    If the tables already exist, and b.nameb is declared as UNIQUE (or PRIMARY KEY), then you can say:
    ALTER TABLE  a
        ADD CONSTRAINT     a_namea_fk
        FOREIGN KEY  (namea)
        REFERENCES b (nameb)
    ;If you had a situation where you really needed to query a table in PL/SQL, and you weren't sure if the query would find anything, you could put the query in its own BEGIN ... EXCEPTION block, and test for NO_DATA_FOUND.
    If you're just checking to see if a row exists or not, you can always write a query that is guaranteed to return exactly 1 row, like this:
    BEGIN
        SELECT  COUNT (*)
        INTO    x
        FROM    b
        WHERE   nameb = :NEW.namea
        AND         ROWNUM  = 1;
        IF x = 0
        THEN  
            ...        -- print msgs, raise exceptions etc
        END IF;
    END;Edited by: Frank Kulash on Nov 14, 2012 9:22 AM
    Added example

Maybe you are looking for

  • How do I delete an app installed with an old iTunes account?

    How do I delete an app installed with an old iTunes account? After syncing my iPhone with iTunes, the app is not listed in the App section.

  • Tv as second monitor not working

    I connect my iMac to my Samsung TV using a displayport to VGA adaptor. It had been working fine up until now. when I put my tv in PC mode it just turns off. Is this a problem wuth the mac or the TV

  • How to edit a post?

    Well just from the topic, can some one tell me how i can edit a post that i posted B4 at any forum? Thanks in advance.

  • Cisco ISE with cisco-av-pair

    Hi All I am deploying a Cisco ISE together with a WLC to provide guest services. After the authentication the users will be redirected to the device registration page, this is done via the radius attribute "cisco-av-pair = url-redirect=https://FQDN:8

  • Execute "emca -config dbcontrol db -repos create" exception

    Hi, I want to recreate OEM configuration, so I execute the above command. The following is the exception: Exception in thread "main" java.lang.NoClassDefFoundError: HTTPClient/ProtocolNo tSuppException at oracle.sysman.emd.targetIntg.agent.AgentTarge