How to create a foreign key constraint on a table nested column

Dear Experts,
I create 2 tables using the object type. the VESSEL_PARAM table contains the list of the parameters allowed.
The table VESSEL_TYPE containe single item we list some parameters.

On this table, I love the column VESSEL_PARAM table VESSEL_PARAM to check if the settings are and the reference value is allowed.
How to create a foreign key?
Here my script that generates this runtime error: 00904. 00000 - '% s: invalid identifier' on this line

ALTER TABLE VESSEL_PARAM_TAB ADD CONSTRAINT FK_VESSEL_TYPE FOREIGN KEY (NAME, DATA_VALUE)
REFERENCES VESSEL_PARAM (PARAM_NAME, LIST_PARAM_VALUE. DATA_VALUE)
CREATE OR REPLACE TYPE OBJ_PARAM_VALUE AS OBJECT 
( 
  DATA_VALUE  VARCHAR2(20)
 ,DESCRIPTION VARCHAR2(125)
) NOT FINAL;
/

CREATE OR REPLACE TYPE LIST_PARAM_VALUE AS TABLE OF OBJ_PARAM_VALUE;
/

-- derive object subtype from object supertype
CREATE OR REPLACE TYPE OBJ_PARAM_NAME UNDER OBJ_PARAM_VALUE (
  NAME VARCHAR2(30)
)NOT FINAL;
/

CREATE OR REPLACE TYPE LIST_PARAM_NAME AS TABLE OF OBJ_PARAM_NAME;
/

Prompt create table VESSEL_PARAM;
CREATE TABLE VESSEL_PARAM (
   PARAM_NAME   VARCHAR2(20) NOT NULL
  ,PARAM_DESC   VARCHAR2(125)
  ,PARAM_VALUE  LIST_PARAM_VALUE
  ,CONSTRAINT PK_VESSEL_PARAM PRIMARY KEY (PARAM_NAME)
) 
NESTED TABLE PARAM_VALUE STORE AS PARAM_VALUE_TAB
TABLESPACE CMS_ADMDATA;
/
ALTER TABLE PARAM_VALUE_TAB ADD CONSTRAINT UN_PARAM_VALUE_TAB UNIQUE (DATA_VALUE);
/
SHOW ERROR;

Prompt create table CMS_ADM.VESSEL_TYPE;
CREATE TABLE CMS_ADM.VESSEL_TYPE (
  VESSEL_TYPE  VARCHAR2(20) NOT NULL
 ,VESSEL_DESC  VARCHAR2(125)
 ,VESSEL_PARAM LIST_PARAM_NAME
 ,CONSTRAINT PK_VESSEL_TYPE PRIMARY KEY (VESSEL_TYPE)
-- ,CONSTRAINT FK_VESSEL_TYPE FOREIGN KEY (VESSEL_PARAM) 
--        REFERENCES VESSEL_PARAM (PARAM_NAME)
) 
NESTED TABLE VESSEL_PARAM STORE AS VESSEL_PARAM_TAB
TABLESPACE CMS_ADMDATA;
/
ALTER TABLE VESSEL_PARAM_TAB ADD CONSTRAINT UN_VESSEL_PARAM_TAB UNIQUE (NAME);
ALTER TABLE VESSEL_PARAM_TAB ADD CONSTRAINT FK_VESSEL_TYPE FOREIGN KEY (NAME,DATA_VALUE) 
        REFERENCES VESSEL_PARAM (PARAM_NAME,LIST_PARAM_VALUE.DATA_VALUE)
/
SHOW ERROR;
Thank you

Salvatore

Could you please indicate your answer as correct if you judge them correct.

Best regards

Mohamed Houri

Tags: Database

Similar Questions

  • Maker of SQL data - how to create the foreign key in the relationship 1 to 1?

    Hi guys...

    I had 2 tables...

    Table 1 - CFR
    -----------------------
    CFR_ID = primary key


    Table 2 - USER_PLAN
    ----------------------------
    User_id = primary key
    PLAN_ID ARGUMENT,
    CFR_ID = reference foreign key (table 1)


    Business flow go like this...
    table insdie CFR, it contains all the documents / transactions of a particular plan user. each time a new transaction occurs for a plan/user, a new CFR_ID / row will be generated.
    After that, the newly generated for the new line, CFR_ID will be updated to the CFR_ID in USER_PLAN


    Thus, there is always a 1 to 1 relationship between table 2, no matter how much CFR_ID is generated for a particular USER_PLAN. as the CFR_ID in the USEr_plan table will always be the last being produced within the table of the CFR.


    However, in the Data Modeler, I am unable to create this foreign key relationship... NO idea how create a 1 on 1 relationship of foreign key? or there is no way...


    Thank you and best regards,
    Noob

    Hey Noob,

    Yes, that's correct.

    Best regards
    Philippe

  • Create a foreign key constraint against a different schema

    Hi all

    I use the oracle 10g r2 on windows 2003 server database.

    I have a table in the HRMS as STAFF.
    I have another INVENTORY schema, where I want to access a column as a foreign key in HRMS. STAFF (STAFF_ID).
    connect hrms/hrms@orcl
    grant select on STAFF to INVENTORY;
    connect inventory/inventory@orcl
    alter table inv_details add constraint fk_inv_hr_staff foreign key (staff_id) references HRMS.STAFF(STAFF_ID);
    Error report:
    SQL Error: ORA-00942: table or view does not exist
    00942. 00000 -  "table or view does not exist"
    What exactly I have to grant so this diagram of the INVENTORY will be able to create a referential constraint?

    Kind regards.

    You must also grant the privilege of REFERENCES.

    See privileges in table 18-2 at http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_9013.htm#BGBCIIEG

    Hemant K Collette

  • How to create a foreign key

    Hai

    I have two table

    Nrgp_main

    Nrgpno here is primary ky

    And NRGP_ITEM

    I need NRGPno as foreign key I dropped it and I now I need to recreate


    I have an error inIt


    ALTER table nrgp_item add constraint
    FK_NRGPITA foreign key (nrgpno) references nrgp_main (nrgpno);


    Error

    FK_NRGPITA foreign key (nrgpno) references nrgp_main (nrgpno)
    *

    ERROR on line 2:
    ORA-02270: no unique or primary key corresponding to this column list


    Concerning

    sRikkanth

    Hello

    You do something like that?

    SQL> create table a(n number primary key);
    
    Table created.
    
    SQL> create table b(n number);
    
    Table created.
    
    SQL> alter table b
      2  add constraint
      3  fk_n foreign key(n) references a(n);
    
    Table altered.
    
    SQL> alter table b
      2  drop constraint fk_n;
    
    Table altered.
    
    SQL> alter table b
      2  add constraint
      3  fk_n foreign key(n) references a(n);
    
    Table altered.
    

    Twinkle

  • Foreign keys of a logical Table

    Hi all

    I want to know in what scenarios, we create the foreign key of a logical Table. Once we have create the foreign key for the logical table, this means he automatically substitute if joins are here.


    Physical table A, B (without physical joins)

    Logic table A, B (B (Sun)--> (Fact) A logical join)

    created the foreign key in the logical table A with b. (A.1 = B.1)

    The RPD will generate sql with A.1 = B.1 join condition for the reports.

    I tried to create the logical foreign key for table logical, I couldn't see any option from the table. Here is his
    http://Tinypic.com/r/jq1gkz/6


    Thank you

    Virat

    In general when we go to the complex joins in the physical layer, we opt for logical foreign key joins in layer MDB, best examples is SCD Type II.

    Physical table A, B (without physical joins)
    --> You must have a physical join so that it can be override by layer MDB

    created the foreign key in the logical table A with b. (A.1 = B.1) the RPD will generate sql with A.1 = B.1 join condition for the reports.
    --> Yes, you can see this join in the physical BI query.

    I tried to create the logical foreign key for table logical, I couldn't see any option from the table. Here is his
    --> 2 cases: 1) you must remove existing logical joins 2) you could not have involved physical layer.

    Hope this helps
    Let me know for questions

    Published by: Srini VIEREN on 18 January 2013 13:29

    BTW: You got a very good reputation, why don't update you your profile to see your name instead of a number

    Published by: Srini VIEREN on 18 January 2013 13:29

  • How to associate an index with a foreign key constraint

    I understand how to associate a primary key constraint or a Unique key constraint index...
    Yet I don't see how to associate the index of a foreign key constraint. Is this possible?

    Thank you
    Bob Larsen

    Hi Bob,

    In Data Modeler, physical model for Oracle primary and unique keys dialog boxes offer an Index field using, which is used to generate the 'using_index_clause' in the DDL for primary and Unique key constraints.
    However the Oracle Database DDL does not have the "using_index_clause" for Foreign Key constraints, thus Data Modeler does not provide this feature for foreign keys.

    So, you will need to create a separate Index that uses the same columns as the foreign key (using the index page of the table properties dialog box in the relational model).

    David

  • create a foreign key

    I'm creating a foreign key between two tables with the following command


    ALTER TABLE core_business.cb_insured_person ADD)
    CONSTRAINT fk_present_prov_cty_cbi
    FOREIGN KEY (present_province_code, present_city_code)
    General_information.cb_city (province_code, city_code) NOVALIDATE REFERENCES);


    I have the DBA privilege and I used to do this work, but when I run stated above I give error of insufficient privileges, how can I solve this problem...


    CREATE THE TABLE CORE_BUSINESS. CB_INSURED_PERSON
    (
    NUMBER OF IP_REGION_FO_CODE (4, 0) NOT NULL
    , IP_CHECK_DIGIT VARCHAR2 (1 BYTE) NOT NULL
    NUMBER OF IP_SERIAL_NO (6, 0) NOT NULL
    NUMBER OF EO_CODE (6: 0)
    NUMBER OF REGISTRATION_CODE (2, 0)
    TITLE VARCHAR2 (5 BYTE)
    , VARCHAR2 (35 BYTE) NAME NOT NULL
    OLD_NIC_NO VARCHAR2 (13 BYTE)
    NEW_NIC_NO VARCHAR2 (15 BYTE)
    VARCHAR2 (6 BYTE) FAMILY_CODE
    SEX VARCHAR2 (1 BYTE)
    RELATIVE_NAME VARCHAR2 (35 BYTE)
    NUMBER OF RELATIONSHIP_CODE (3, 0)
    DATE_OF_BIRTH DATE
    DATE_OF_JOINING_EOBI DATE
    PRESENT_ADDRESS VARCHAR2 (100 BYTE)
    NUMBER OF PRESENT_PROVINCE_CODE (2, 0)
    NUMBER OF PRESENT_CITY_CODE (5, 0)
    NUMBER OF PRESENT_POST_CODE (5, 0)
    PRESENT_TELEPHONE VARCHAR2 (30 BYTE)
    CONSTRAINT PK_CB_INSURED_PERSON PRIMARY KEY
    (
    IP_REGION_FO_CODE
    IP_CHECK_DIGIT
    IP_SERIAL_NO
    )
    ENABLE
    )
    LOGGING
    TABLESPACE "EOBI.
    PCTFREE 10
    INITRANS 1
    STORAGE
    (
    747634688 INITIAL
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    USER_TABLES KEEP
    );


    CREATE TABLE GENERAL_INFORMATION. CB_CITY
    (
    NUMBER OF PROVINCE_CODE (2, 0) NOT NULL
    NUMBER OF CITY_CODE (5, 0) NOT NULL
    , NAME VARCHAR2 (25 BYTE) NOT NULL
    AREA_CODE VARCHAR2 (6 BYTE)
    VARCHAR2 (1 BYTE) STATUS NOT NULL
    , CREATED_BY VARCHAR2 (10 BYTE) NOT NULL
    CREATED_DATE DATE NOT NULL
    , MODIFIED_BY VARCHAR2 (10 BYTE) NOT NULL
    MODIFIED_DATE DATE NOT NULL
    NUMBER OF DIVISION_CODE (5, 0)
    NUMBER OF DISTRICT_CODE (5, 0)
    CONSTRAINT PK_PRV_CTY PRIMARY KEY
    (
    PROVINCE_CODE
    CITY_CODE
    )
    ENABLE
    )
    LOGGING
    TABLESPACE "EOBI.
    PCTFREE 10
    INITRANS 1
    STORAGE
    (
    81920 INITIAL
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    DEFAULT USER_TABLES
    );


    CREATE A UNIQUE GENERAL_INFORMATION INDEX. CB_CITY_PK ON GENERAL_INFORMATION. CB_CITY (NAME ASC)
    LOGGING
    TABLESPACE "EOBI_IDX".
    PCTFREE 10
    INITRANS 2
    STORAGE
    (
    65536 INITIAL
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    DEFAULT USER_TABLES
    );

    CREATE A UNIQUE GENERAL_INFORMATION INDEX. CB_CITY_UK ON GENERAL_INFORMATION. CB_CITY (CSA, CSA CITY_CODE PROVINCE_CODE)
    LOGGING
    TABLESPACE "EOBI_IDX".
    PCTFREE 10
    INITRANS 2
    STORAGE
    (
    65536 INITIAL
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    DEFAULT USER_TABLES
    );

    The schema CORE_BUSINESS has REFERENCES and privileges SELECT on the table that you want to refer to the foreign key constraint?

  • Can we create a foreign key by using built in functions?

    Hi all

    I'm in the need to create a foreign key referring to an expression of a column in another table.

    For example, I try below and I got some errors.

    CREATE TABLE TABLE_A

    (

    student_id VARCHAR2 (30),

    student_name VARCHAR2 (100),

    CONSTRAINT fk_A FOREIGN KEY (student_id) REFERENCES TABLE_B (UPPER (column_name))

    );

    Please suggest if it is possible that a foreign key could be made in an expression or not?

    2761969 wrote:

    Hi all

    I'm in the need to create a foreign key referring to an expression of a column in another table.

    For example, I try below and I got some errors.

    CREATE TABLE TABLE_A

    (

    student_id VARCHAR2 (30),

    student_name VARCHAR2 (100),

    CONSTRAINT fk_A FOREIGN KEY (student_id) REFERENCES TABLE_B (UPPER (column_name))

    );

    Please suggest if it is possible that a foreign key could be made in an expression or not?

    No - it isn't.

    You can, however, create a VIRTUAL column in the parent table, and then create a foreign key that references.

  • Entity Association depends on foreign key constraint?

    Hello

    I use JDeveloper 10.1.3.4 and have a question, as shown in the subject of this announcement. By a design flaw, I added a foreign key on a table constraint at the level of the database for any purpose other than to achieve a relationship between master/detail your. Now the foreign key constraint fell to remedy the irregularity, but I don't know if the application is not a problem on the road.

    The application in question has a table named BILL and another table called VALIDATIONS, both with the same primary key composite (LDAP_UID, TERM), where we hear per semester.

    BILL is on students, the balance they have, etc. VALIDATION records the commitment, students make:
    BILL
    ------------------------------------------------
    LDAP_UID       TERM      BALANCE
    -------------  --------  --------
    john.miller    200902       1500
    
    
    VALIDATIONS
    ------------------------------------------------
    LDAP_UID       TERM      CONFIRM_NUMBER
    -------------  --------  --------------
    john.miller    200902    0901100005
    The foreign key constraint has been added on the table of VALIDATION, validations (LDAP_UID, TERM) reference (LDAP_UID, TERM) BILL. When the data model is accumulated in the application, an entity association was created automatically for this foreign key constraint, and then a link has been created on the association of the entity to achieve the effect mater-detail of the application:
    Table:               BILL
    Table:               VALIDATIONS
    Foreign Key:         VALIDATIONS(LDAP_UID, TERM) references BILL(LDAP_UID, TERM)
    Entity object:       Bill
    Entity object:       Vallidations
    Entity Association:  ValidationsBillFkAssoc (based on the foreign key)
    View object:         LoggedInStudent (from Bill)
    View object:         OneValidation (from Validations)
    View link:           ValidationByOneStudent (based on ValidationsBillFkAssoc.  This achieves master/detail
                                                 between LoggedInStudent and OneValidation)
    This foreign key is now asking problem and should be deleted: Bill table contains the data from more than three semesters, whereas student commitments cumulatively saved in the table of VALIDATIONS must be maintained permanently. When data from older semesters are unloaded from the table of BILL, the lines stored in the table of VALIDATION are orphaned.

    I thought that the link of the view and the association of the entity dependent on the foreign key, so I removed before dropping the foreign key in the order listed here:
    Removed usage of of the VO (OneValidation) from the application module
    Deleted the view link (ValidationByOneStudent)
    Deleted the entity association (ValidationsBillFkAssoc)
    Dropped the foreign key in the database
    The master/detail relationship between the two your is still necessary. I added the link display, which now is based on common attributes (LdapUid, term) between the two, rather than based on the association of the entity. The modified application works very well with the database has changed and now the rows in the table of VALIDATION will not be an orphan.

    What is interesting and also troubling is that when I run a copy of the application which has been registered before these amendments, on the basis of data which dropped the foreign key constraint, the application still works, with the master-detail and everything. And the dependencies do not seem to matter. But isn't it?

    My question is: an entity association requires a corresponding foreign key in the database? If I use the copy of the application before the changes, it will be OK or it will cause unforeseen problems on the road?

    Thank you!

    Newman

    Edited by: J. Newman, October 6, 2009 10:31

    Hello

    If you've proven yourself that in fact there is no dependency between the association and the foreign key constraint. in fact you can create everything that (the primary keys, foreign keys, other constraints) only for your same features if you have nothing
    defined in database tables, which is obviously not right approach. and JDeveloper tells you only about the dependence of its use (if you want to delete something that is used some part... e. g VL in AM, EO in VO, VO in AM...)
    just to note - it is important to synchronize your OA if you change the definition of the data table. for example if you remove the foreign key of the table then right-click on EO and chose to sync - JDeveloper should acknowledge and ask you
    If you want to remove this constraint of EO.

    Kind regards

    Branislav

  • SQL statement error INSERT The conflicted with the FOREIGN KEY constraint

    I recently installed a reporting for vmware vsphere software, but I get a SQL error. I opened a request for assistance with vmware, but so far they have not come up with a solution. The error is caused by: com.microsoft.sqlserver.jdbc.SQLServerException: instruction INSERT The conflicted with the FOREIGN KEY constraint 'FK_CB_VSM_NETWORK_VC_ID '. The conflict occurred in database 'VCChargebackVCC02', table "dbo." " CB_VSM_SERVER', column 'VC_ID '. I don't know a lot about SQL, so I'm lost in the extent of troubleshooting is concerned. If anyone has any ideas I'd love to hear them.

    SQL questions are better posed on Technet.  They are better equipped to manage the

    http://social.technet.Microsoft.com/forums/en-us/categories/

  • Foreign key constraint, not recognized during the synchronization of data with the model dictionary

    Hello

    Data Modeler is a foreign key constraints do not recognize when synchronizing data with the model dictionary, although the foreign key is there (in the database that a data dictionary is read). I can't find any criterion when a foreign key is not recognized by the Data Modeler. Are there limits to the length of the attribute, or the number of columns in a foreign key, or other limitations which may lead to this behavior not to recognize a fk by Data Modeler? I have columns more than 32 characters. I compared with the fk is recognized by DM, but I can't find anything that indicates why it is not recognized.

    I wonder if someone also has constraints of foreign keys that are not recognized in the comparison of data bases and model?

    Thank you

    Robert

    Hi Robert,.

    Thanks for the comments, I logged a bug.

    Philippe

  • in the setup of freshclient and datadownload foreign key constraint

    Hello

    I use oracle database 10 GB lite R3 and oracle database 10g R2 as the database back end for her. When I do the client installation fees and datadownload of the client machine I don't get the foreign key constraint in the machune of customer. can someone explain to me the reason for this?

    Published by: 793097 on November 9, 2010 21:57

    The Mobile Server deploy foreign keys out of the box. You will need to add them through scripting. You can add scripts in the MDW or API.

    Let me know if you need an example.

  • Details of the foreign key constraints

    Why foreign key constraints is not ongoing validation in case of null values?
    For example, in the table EMP and DEPT table, EMP. References DEPTNO Dept. DEPTNO.
    But I am able to insert rows into the EMP table that contains nulls for EMP. DEPTNO.

    Prasath N wrote:
    Why foreign key constraints is not ongoing validation in case of null values?
    For example, in the table EMP and DEPT table, EMP. References DEPTNO Dept. DEPTNO.
    But I am able to insert rows into the EMP table that contains nulls for EMP. DEPTNO.

    I guess he's saying essentially that a foreign key must have a parent key or can be an orphan. But may not be a key that is not listed in the parent.

    And also NULL is neither equal to anything, nor does not correspond to something.

    But still, you can put a NOT NULL constraint if you do not want your foreign key to contain orphaned records.

  • Is this a BUG?  Export of data besides the foreign key constraints

    I use SQL Developer 1.5.4 with patches installed 59,47 and 59,59. I want to do an export of database from a scheme of 10 g XE and include all objects in the DOF resulting. So I select ALL the checkboxes in the Export Wizard and when I get to step 3 to specify the objects, I don't see any of my constraints in the list box... not foreign key constraints, without constraints of primary key, without check constraints, nothing. Is this a bug, or is there a workaround, or which could possibly hurt? We want to be able to use the database export function to easily transport and track the changes to our entire schema using source control compares.

    Any help or suggestions replacement would be apprieciated.

    Thank you
    Matt

    Bug 8679318 follows this question

  • foreign key with the apps table

    Hello world

    I created a custom table and I want to create a foreign key with per_all_people_f.

    Code:
    ALTER TABLE xxsshr.xxsm_sshr_hr_approver
    ADD CONSTRAINT fk_person_id
    FOREIGN KEY (person_id)
    REFERENCES HR. PER_ALL_PEOPLE_F (person_id)

    However, I get ora-00942: table or view does not exist.

    We use 11.5.10 and g 10 dB

    Thanks for any help...

    Elmer

    The XXSSHR account will need reference and select the privileges (and maybe others) on the PER_ALL_PEOPLE_F table. The ALTER TABLE statement must be run under the account XXSSHR after the above privileges are granted.

    HTH
    Srini

Maybe you are looking for