But UNIQUE constraint with a condition?

Hello!

Is it possible to define a unique constraint in a table that would apply only to a condition (according to the content of the line only)?

For example:
CREATE TABLE example
(
  pk number,
  a number,
  b number,
  c VARCHAR2(10),
  x number
);
 
The constraint would be UNIQUIE (a, b), but only when x is > 10.
So if x is not greater than 10, then the same values for a and b nd should be allowed.

Maybe with a view?


Like this?
create view example_view  ( unique (a,b)) AS
select a,b from example where x > 10
 with read only; -- ??? needed? 
Kind regards
David

You can create an index based on a function. This takes advantage of the fact that Oracle does not store the NULL entries in an index b-tree

CREATE UNIQUE INDEX idx_example
    ON example(
      (CASE WHEN x > 10 THEN a ELSE NULL END),
      (CASE WHEN x > 10 THEN b ELSE NULL END)
    );

Justin

Tags: Database

Similar Questions

  • Unique constraint with condition - validation of EO levels

    I have a table
    create the CUSTOMER table (key number primary client_prefix,)
    client_suffix Varchar2,
    Number of NIN,
    status number (1).
    . . . . . . . .
    . . . . . . . .);


    I have an obligation to respect a unique constraint where NIN THAT must be unique for the Client_suffix, but the issue is that customers in rejected status
    (status = 9 means that the customer is in rejected status) should be ignored.

    It is a new customer can be created with the same client_suffix, combination of NIN has provided other customers
    with the same combination have rejected status. If not, can not be created.

    I've already implemented this in the database level. I would like to know how this can be implemented as a validation of EO levels

    Jdev version 11.1.2.0.0

    No, you don't need to do...

    Use this technique: http://docs.oracle.com/cd/E26098_01/web.1112/e16182/bcadvgen.htm#sthref439

    John

  • Unique constraint with conditions?

    Hi all!

    I have the following scenario... I need column UNIQUE Serial_number forced but only when the STATUS column = 'Y '. Serial_number can be non-unique, where the STATE has another value or is set to null. So, I couldn't en with this:

    SERIAL_NUMBER | STATUS
    --------------------------------------
    123456789 N
    123456789 N
    123456789 IS

    but a new line with 123456789 and 'Y' should not be allowed.

    Is this possible with a UNIQUE constraint, or what I have to set in a trigger? I was playing with the UNIQUE constraint for a while, but neither DECODE, WHERE clauses seem to be accepted...

    Thanks in advance!

    Try this:

    create unique index a1 on tab(case when STATUS = 'Y' then SERIAL_NUMBER else null end);
    

    Amiel

  • Question of the unique constraint with finance charge

    Hi friends,

    As part of the implementation of 11 g BIAPPS-ODI during the execution of a finance charge is my load of CM plan failed with the error like below

    ODI-1519: series step 'Load start Plan (InternalID:1242500)' failed because step 'Refresh Global Variable (InternalID:1243500)' child is in error.

    ODI-1519: series step 'Refresh Global Variable (InternalID:1243500)' failed because the step child "Warehouse loading Phase (InternalID:2336500)" is a mistake.

    ODI-1519: series step "Warehouse loading Phase (InternalID:2336500)" failed because the child step "SIL 1 charge (InternalID:2337500)" is a mistake.

    ODI-1519: series step '1 SIL Load (InternalID:2337500)' failed, because the child step '2 group of dimensions of SIL (InternalID:2338500)' is a mistake.

    ODI-1519: series step '2 group of dimensions of SIL (InternalID:2338500)' failed because the child step "Parallels - independent DimGroup (InternalID:2346500)" is a mistake.

    ODI-1518: parallel step 'Parallels - independent DimGroup (InternalID:2346500)' failed. level of 1 child by mistake, which is more than the maximum number of allowed errors (0) defined for parallel step.  Has no measures of the child: 3 SIL Dims POSHIER_DIM (InternalID:2369500)

    ODI-1519: series step '3 SIL Dims POSHIER_DIM (InternalID:2369500)' failed because the child "POSHIER_DIM (InternalID:2372500)" is a mistake.

    ODI-1519: series step "POSHIER_DIM (InternalID:2372500)" failed because step "SIL_PositionDimensionHierarchy (InternalID:2377500)" child is in error.

    ODI-1217: SILOS_SIL_POSITIONDIMENSIONHIERARCHY Session (4278500) fails with return code 1.

    ODI-1226: SIL_PositionDimensionHierarchy.W_POSITION_DH step fails after 1 attempt.

    ODI-1240: Flow Run SIL_PositionDimensionHierarchy.W_POSITION_DH fails during an operation of integration. This flow of charge table target W_POSITION_DH.

    ODI-1228: SIL_PositionDimensionHierarchy.W_POSITION_DH (integration) of the task fails when connecting ORACLE target BIAPPS_DW.

    Caused by: java.sql.SQLIntegrityConstraintViolationException: ORA-00001: unique constraint (DEV_DW. W_POSITION_DH_U2) violated

    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:462)

    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:405)

    at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:931)

    at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:481)

    at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:205)

    at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:548)

    at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:217)

    at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1115)

    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1488)

    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3769)

    at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3954)

    at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1539)

    at oracle.odi.runtime.agent.execution.sql.SQLCommand.execute(SQLCommand.java:163)

    at oracle.odi.runtime.agent.execution.sql.SQLExecutor.execute(SQLExecutor.java:102)

    at oracle.odi.runtime.agent.execution.sql.SQLExecutor.execute(SQLExecutor.java:1)

    at oracle.odi.runtime.agent.execution.TaskExecutionHandler.handleTask(TaskExecutionHandler.java:50)

    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:2093)

    at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java:1895)

    to oracle.odi.runtime.agent.processor.impl.StartScenRequestProcessor$ 2.doAction(StartScenRequestProcessor.java:580)

    at oracle.odi.core.persistence.dwgobject.DwgObjectTemplate.execute(DwgObjectTemplate.java:216)

    at oracle.odi.runtime.agent.processor.impl.StartScenRequestProcessor.doProcessStartScenTask(StartScenRequestProcessor.java:512)

    to oracle.odi.runtime.agent.processor.impl.StartScenRequestProcessor$ StartScenTask.doExecute (StartScenRequestProcessor.java:1068)

    at oracle.odi.runtime.agent.processor.task.AgentTask.execute(AgentTask.java:137)

    to oracle.odi.runtime.agent.support.DefaultAgentTaskExecutor$ 2.run(DefaultAgentTaskExecutor.java:82)

    at java.lang.Thread.run(Thread.java:662)

    How to solve the question above using ODI 11 g. I'm using Oracle ERP R12.1.3 as a source of data for this.

    Thanks in advance.

    Kind regards

    Saro

    What is the result of a query on table W_POSITION_DH or W_POSITION_D duplicate?

    Naeem

  • explain query plan uses no unique index with where condition

    Hi all

    I use in the 10.2.0.5 oracle database Enterprise edition 64-bit on 64-bit windows server 2008.

    I'm following this tutorial on my own table

    Guide to understanding Oracle QUERY PLAN - 10 minutes

    my questions are below

    Analyze table LIB_CLASSIFICATIONS compute statistics;
    explain plan for  SELECT class_id  FROM lib_classifications WHERE class_no = '538' ;
    select * from table(dbms_xplan.display);
    

    the result is less than

    Hash value of plan: 3022072076

    -----------------------------------------------------------------------------------------

    | ID | Operation | Name                | Lines | Bytes | Cost (% CPU). Time |

    -----------------------------------------------------------------------------------------

    |   0 | SELECT STATEMENT |                     |     1.    10.     5 (0) | 00:00:01 |

    |*  1 |  TABLE ACCESS FULL | LIB_CLASSIFICATIONS |     1.    10.     5 (0) | 00:00:01 |

    -----------------------------------------------------------------------------------------

    Information of predicates (identified by the operation identity card):

    ---------------------------------------------------

    1 - filter ("CLASS_NO" = '538')

    DESC LIB_CLASSIFICATIONS

    Name of Type Null

    ----------------- -------- -------------

    CLASS_ID NOT NULL NUMBER (10)

    CLASS_DESC VARCHAR2 (50)

    REMARKS VARCHAR2 (250)

    CLASS_NO VARCHAR2 (20)

    CLASS_TYPE VARCHAR2 (10)

    CREATE_USER VARCHAR2 (10)

    MODIFY_USER VARCHAR2 (10)

    CREATE_DATE DATE

    MODIFY_DATE DATE

    CLASS_CATEGORY_ID VARCHAR2 (10)

    class_id has a primary key.

    now when I remove the condition where the query, the result is lower;

    Analyze table LIB_CLASSIFICATIONS compute statistics;
    explain plan for  SELECT class_id  FROM lib_classifications ;
    select * from table(dbms_xplan.display);
    

    the result is less than

    Hash value of plan: 262704430

    ------------------------------------------------------------------------------------

    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |

    ------------------------------------------------------------------------------------

    |   0 | SELECT STATEMENT |             |  1558.  6232.     2 (0) | 00:00:01 |

    |   1.  FULL RESTRICTED INDEX SCAN FAST | SYS_C005653 |  1558.  6232.     2 (0) | 00:00:01 |

    ------------------------------------------------------------------------------------

    now it's using indexes with INDEX FAST FULL SCAN.

    I need the index using the WHERE condition as well.

    How to do this?

    Thank you.

    you have indexes on the column class_id not on class_no column how u would expect index to use when there is no index on the column class_no

  • Unique index with TRIM

    I want to create a unique constraint with TRIM, I get the error message. Is there a way...
    ALTER TABLE core_business.cb_pensioner ADD CONSTRAINT unique_claim_no UNIQUE(TRIM (claim_no))   deferrable initially deferred NOVALIDATE;
    
    ORA-00904: : invalid identifier

    Pre 11g - unique index; 11g go - virtual columns.

    SQL> create table t1
      2  (col1 varchar2(10));
    
    Table created.
    
    SQL> alter table t1 add constraint uk_t1 unique (trim(col1));
    alter table t1 add constraint uk_t1 unique (trim(col1))
                                                *
    ERROR at line 1:
    ORA-00904: : invalid identifier
    
    SQL> create unique index i1 on t1 (trim(col1));
    
    Index created.
    
    ... virtual column method ...
    
    SQL> drop index i1;
    
    Index dropped.
    
    SQL> alter table t1 add col2 as (trim(col1));
    
    Table altered.
    
    SQL> alter table t1 add constraint uk_t1 unique (col2);
    
    Table altered.
    
    SQL> insert into t1 (col1) values ('1');
    
    1 row created.
    
    SQL>  insert into t1 (col1) values ('1  ');
     insert into t1 (col1) values ('1  ')
    *
    ERROR at line 1:
    ORA-00001: unique constraint (RIMS.UK_T1) violated
    
    SQL> select * from t1;
    
    COL1       COL2
    ---------- ----------
    1          1
    
    SQL> 
    
  • Retrieve values with a unique constraint

    All,

    It may be a stupid request and I think too speak of it. But, for some reason, I am unable to write a query to accomplish my task.

    I have the T table with some columns and the columns c1, c2, c3 are part of a composite unique constraint. Now I'm updating the value c3 from 52 to 51. But, when I do an update like:

    Update T set c3 = 51 where c3 = 52;

    I get a Unique constraint violation error.

    So, I need to know what are the values of repetition that might be causing this?

    Thanks in advance guys.

    34a22dde-3108-4F05-BE72-eb1043d28314 wrote:

    All,

    It may be a stupid request and I think too speak of it. But, for some reason, I am unable to write a query to accomplish my task.

    I have the T table with some columns and the columns c1, c2, c3 are part of a composite unique constraint. Now I'm updating the value c3 from 52 to 51. But, when I do an update like:

    Update T set c3 = 51 where c3 = 52;

    I get a Unique constraint violation error.

    So, I need to know what are the values of repetition that might be causing this?

    Thanks in advance guys.

    An inelegant way...

    select *
    from your_table tab1
    where (tab1.c1,tab1.c2) in
    (
    select tab2.c1, tab2.c2
    from your_table tab2
    where tab2.c3 = 52
    )
    where tab1.c3 = 51;
    
  • Adding a UNIQUE CONSTRAINT to an existing column with duplicate values

    Oracle Forums Hello, I have a table that contains rows 11 901. I tried to define the UNIQUE constraint on the column of xcode, but encountered an error: the column already contain duplicates! I rescued following SQL 'SELECT COUNT (*) FROM States;' the result is 11 901 and 'SELECT COUNT (DISTINCT (xcode)) FROM States;' the result is 11 680. So to enforce this unique key I have to remove the 221 lines. Please how can I do this?

    REMOVE duplicates...

    For example, as

    delete from your_table t
    where rowid <
       (
       select max(rowid)
       from your_table r
       where t.unique_column = r.unique_column);
    

    Thne create the constraint.

  • Need help with PK_REV_COL unique constraint violation

    We receive a SNPW. Violation of unique constraint of PK_REV_COL when you try to reverse a pipe delimited source file. There is no column twice in the source file name, but the same column names are used in several different input files. Does anyone have a solution to this problem?

    Hello

    Tryied to reproduce such behaviour on my side, I'm was not possible for me.

    The only one that occurs to me is, drop the current data store and recreate on...

    Cezar Santos
    [www.odiexperts.com]

  • correct handling of foreign keys in unique constraints for operations ON DELETE SET NULL

    During my troubleshooting at a client site, I came across an interesting setup where I would like to ask your opinion.


    Consider two tables ADTB and TBLB.

    ADTB:

    INT COLA1

    COLA2 INT

    TBLB:

    COLB1 INT

    COLA2 is COLB1 as a foreign key ON DELETE SET NULL value.

    COLA1 and COLA2 are combined into a UNIQUE for the BATTERY constraint.

    I have two records of TBLB:

    (1)

    (2)

    and two DRUM recordings:

    (1, 1)

    (2, 2)

    so far, all the constraints are valid.

    During my research, I learned that I can not put COLA2 null in ADTB for two lines at the same time:

    TBLA UPDATE set COLA2 = NULL where COLA1 = 1;

    -> OK

    TBLA UPDATE set COLA2 = NULL where COLA1 = 2;

    -> VIOLATED UNIQUE CONSTRAINT

    Unfortunately, it's something my application needs, anyway. In order to get this resolved, but I try to understand, what would happen if I:

    REMOVE THE TBLB;

    ?

    It should set COLA2 in ADTB "Null" on the two lines, which is not allowed due to the UNIQUE CONSTRAINT.

    Can someone shed light on this issue? Thank you.


    Yours,

    Ronny

    Unfortunately, as you say, you can't not NULL values in such a unique constraint.  It would be the same as if you had a composite primary key and try to allow one of the columns will be null in several rows with the same value in the other column.  NULL is treated as an "unknown" value, it is possible that it could be the same value (it may or may not be, but Oracle does not know), so it must assume that it might be and that's why treat it as if there is the potential for a duplicate... so it's not unique.

    In short, do not allow null values in your unique constraints.

    The default is in the drawing, not in the way that Oracle is the treatment.  Fix the design if you do not have NULL values.

    In terms of relational database design, it seems that you are trying to transform the 1:M relations M:M relations, and which requires an intermediate table if you have M:1 and 1:M between 3 tables instead.

  • How to display a validation on a modal dialog error based on a unique constraint?

    Hi all

    Apex 4.1

    See example on apex.oracle.com:

    Workspace: EDIAZJORGE

    User name: TEST

    Password: test123

    Application: 55036 - Validation of modal Page

    I have a page with two elements, to make and model, where the user will be able to enter the model, say, a car and use a pick to dolist. If make does not exist, the user can click on the [+] button that opens a modal dialog box to add a new do.

    Everything works fine except when I try to insert a double do, which triggers a unique constraint violation error:

    AJAX call back Server error ORA-00001: unique constraint (EDIAZJORGE. MAKE_UK1) violated to execute the PL/SQL Code

    I want to enter this event and inform the user about an error inside the modal dialog box, but I don't know what is the best way to achieve this. My guess is that I'll have to make an Ajax call to run an application process and capture the exception of DUP_VAL_ON_INDEX, but I'm not very familiar with the Ajax part.

    Any suggestions?

    Thank you

    Erick

    I'm sorry Erick, I was in error. You always get an alert but with a nicer message. The actions of builtin DA do not allow interaction with them, so no way to manage the return of ourselves.

    In light of this, I copied the page in enforcement 77635 1-2 and made some changes to it. Basically, I copied the code to Jorge and modified so that it uses $.ajax instead of apex.server.process. I much prefer it to htmldb_Get - you shouldn't really use it either. More $.ajax has the advantage of this apex.server.process is based on it. That should work well on 4.1.

    Sorry Jorge, won't steal the Thunder, I guess I was... bored? And decided to do some apex?

  • The charge would be created with the unique package with date id

    Hi all

    Thanks in advance,

    IAM new to ODI, in my process I dnt know below two constaraints how to do, please help me in this regard...

    1. the load would be created with the id of a single lot with the date and
    stamp under the unique number (when the load data from source to target).
    2. HIGHLAND field would have the line number incremented from
    .001 when records are inserted in the table

    30021986 wrote:
    Hello

    Thanks for the reply, my requirement is,
    1.i have field JELN in the target table, in that line number is incremented from de.001 in the table. (Field JELN would have the incremented number line from de.001 when the rows are inserted in the table)

    -> for what I had done using sequenceing odi_sequence craeating, but it will give higher error.
    and the second condition is

    Never use ODI sequence unless you do business with a technology that has no native sequence is
    (eg files). Most of the RDBMS has their own sequence, and you use these alone.
    For oracle, you must use . NEXTVAL in the field mapping. Be sure to run on the target.

    2. when iam loading the data from the source to target a unique batch number must be generated with the date and time stamp (the load would be created with the unique package with date id and + *)
    timestamp in the unique number +) *.

    You can use SYSTIMESTAMP in this area and do not forget to run on the target.

  • Indexes and UNIQUE constraints

    For a TEST table (col1, col2, col3,...), I put the UNIQUE constraint as follows:

    ALTER table TEST add constraint test_uniq UNIQUE col1, col2, col3);

    It is said that when the UNIQUE constraint is created, ORACLE also creates an index on (col1, col2, col3) automatically. But sometimes, I use only one of the columns in the WHERE clause as col1 = xxx, or col2 = yyy.

    Create separate indexes, one for col1 and col2? I think that even if the creation of the UNIQUE constraint also created an index. But this index is a composite index that is for the dosage of col1, col2 and col3 simultaneously (is that correct)? If so, create an index for col1 and col2 will be necessary?



    Thank you for helping.

    Scott

    If there is an index on (col1, col2, col3) and ask about col1, the index will be used.

    If you have questions about col2, it can (index skip scan) or maybe not.

    If you ask about col3 then it will not be used.

    So if you think that there will be queries with col3 in where clause and they can benefit from an index, you can create it.

  • Name of the PK, unique constraints and to support the index

    I want to have my primary key constraint and index support share of the same name, IE:
    CREATE UNIQUE INDEX MYTABLE_PK ON MYTABLE(...);
    ALTER TABLE MYTABLE ADD CONSTRAINT MYTABLE_PK PRIMARY KEY(...);
    Without definition explicit a unique index using the relational model, the generated DDL added 'X' for the name of the index:
    CREATE UNIQUE INDEX MYTABLE_PKX ON MYTABLE(...);
    ALTER TABLE MYTABLE ADD CONSTRAINT MYTABLE_PK PRIMARY KEY(...);
    I tried to add an index unique explicit to the table, but he changed the name (adds "v1") when I leave the table editor:
    CREATE UNIQUE INDEX MYTABLE_PKv1 ON MYTABLE(...);
    ALTER TABLE MYTABLE ADD CONSTRAINT MYTABLE_PK PRIMARY KEY(...);
    I have the same problem with index & unique constraints.

    Issues related to the:
    Can I generate DDL with name matching? "v1" thing seems unlikely, he doesn't want not myself save the definition as I want.
    Where are the transformations of naming for this location? I found tools, preferences, and Data Modeling/naming Standards/Templates but this nugget does nto seem to be there.

    Thank you.

    Hi Mike,.

    The Production data release model 3.1 has been updated to allow constraints unique and primary and their indexes share the same name.

    David

  • composite unique constraint on the values of parent and child?

    Is it possible to have a composite unique constraint that contains the values of the child elements? The example below has the "child" elements are offline, but it's preferred, but optional, I know that you can have a unique constraint in the set of tables without using a reference table that contains the constraint and the two columns. How xdb manages this requirement?

    permit:
    <parent ID="1">
       <child><name>test1</name></child>
       <child><name>test2</name></child>
    </parent>
    <parent ID="2">
       <child><name>test1</name></child>
       <child><name>test2</name></child>
    </parent>
    not allowed:
    <parent ID="1">
       <child><name>test1</name></child>
       <child><name>test1</name></child>
    </parent>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
               xmlns:xdb="http://xmlns.oracle.com/xdb"
               xdb:storeVarrayAsTable="true"
               elementFormDefault="qualified">
        
        <xs:element name="parent" type="Parent_T"
            xdb:columnProps="CONSTRAINT parent_pkey PRIMARY KEY (XMLDATA.ID)"
            xdb:defaultTable="PARENT"/>
    
        <xs:complexType name="Parent_T" xdb:SQLType="PARENT_T" xdb:maintainDOM="false">
            <xs:sequence>
                <xs:element name="child" type="Child_T" minOccurs="1" maxOccurs="unbounded" xdb:SQLName="CHILD"
                          xdb:SQLInline="false" xdb:defaultTable="CHILD" "/>
            </xs:sequence>
            <xs:attribute name="ID" xdb:SQLName="ID" use="required" />
        </xs:complexType>
        
        <xs:complexType name="Child_T" xdb:SQLType="CHILD_T">
           <xs:sequence>
             <xs:element name="name" type="xs:string" xdb:SQLName="NAME"/>
           </xs:sequence>
         </xs:complexType>     
    </xs:schema>
    xdb:columnProps = "CONSTRAINT parent_pkey PRIMARY KEY (XMLDATA.ID), * UNIQUE (XMLDATA.» "Child.Name) *" triggers the non-existent attribute


    A possible solution would be to copy the value of the primary key parent of the child element, then I could create a composite unique constraint using only the values of the child. However, I have this same requirement elsewhere in my lowest nested schema, and it can become messy / bad design with cascading of all primary keys on the schema. For example, I have a recursive element in which two attributes must be unique only within the parent company:
    <parent id="1">
       <child a="1" b="1">
          <child a="1" b="2">
             <child a="1" b="1" /> *not allowed
          </child>
       </child>
       <child a="1" b="2" /> *not allowed
    </parent>
    Possible solution:
    <child a="1" b="2" parent_id="1" />
    <xs:complexType name="Child_T>
       <xs:sequence>
          <xs:element name="child" xsd:SQLInline="false" xsd:columnProps="UNIQUE(XMLDATA.a,XMLDATA.b,XMLDATA.parent_id)" minOccurs="0" maxOccurs="unbounded" type="Child_T">
       </xs:sequence>
       </xs:element
    </xs:complexType>
    Is there a better design?

    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi 
    PL/SQL Release 10.2.0.4.0 - Production                           
    CORE     10.2.0.4.0     Production                                       
    TNS for Linux: Version 10.2.0.4.0 - Production                   
    NLSRTL Version 10.2.0.4.0 - Production 

    You can do something like this:

    SQL> DECLARE
      2
      3    xsd_doc xmltype := xmltype('
      4  
      5    
      6      
      7        
      8          
      9        
     10      
     11    
     12    
     13      
     14        
     15          
     16        
     17      
     18    
     19    
     20      
     21        
     22          
     23        
     24        
     25      
     26    
     27    
     28      
     29        
     30          
     31        
     32      
     33    
     34  ');
     35
     36  BEGIN
     37
     38    dbms_xmlschema.registerSchema(
     39      schemaURL => 'test_parent.xsd',
     40      schemaDoc => xsd_doc,
     41      local => true,
     42      genTypes => true,
     43      genbean => false,
     44      genTables => false,
     45      enableHierarchy => dbms_xmlschema.ENABLE_HIERARCHY_NONE
     46    );
     47
     48  END;
     49  /
    
    PL/SQL procedure successfully completed
    
    SQL> CREATE TABLE my_xml_table OF XMLTYPE
      2  XMLTYPE STORE AS OBJECT RELATIONAL
      3  XMLSCHEMA "test_parent.xsd"
      4  ELEMENT "root"
      5  VARRAY xmldata."parent" STORE AS TABLE my_parent_tab
      6  (
      7    VARRAY "child" STORE AS TABLE my_child_tab
      8  )
      9  ;
    
    Table created
    
    SQL> ALTER TABLE my_parent_tab ADD CONSTRAINT parent_uk UNIQUE (nested_table_id, "ID");
    
    Table altered
    
    SQL> ALTER TABLE my_child_tab ADD CONSTRAINT child_uk UNIQUE (nested_table_id, "name");
    
    Table altered
     
    

    Then:

    SQL> insert into my_xml_table values (
      2  xmltype('
      3     test1
      4     test2
      5  
      6  
      7     test1
      8     test2
      9  ')
     10  );
    insert into my_xml_table values (
    *
    ERREUR à la ligne 1 :
    ORA-00001: violation de contrainte unique (DEV.PARENT_UK)
    
    SQL> insert into my_xml_table values (
      2  xmltype('
      3     test1
      4     test1
      5  
      6  
      7     test1
      8     test2
      9  ')
     10  );
    insert into my_xml_table values (
    *
    ERREUR à la ligne 1 :
    ORA-00001: violation de contrainte unique (DEV.CHILD_UK)
    
    SQL> insert into my_xml_table values (
      2  xmltype('
      3     test1
      4     test2
      5  
      6  
      7     test1
      8     test2
      9  ')
     10  );
    
    1 ligne créée.
    

    http://download.Oracle.com/docs/CD/B19306_01/AppDev.102/b14259/xdb06stt.htm#sthref987

Maybe you are looking for