Put a unique constraint on column if duplicate data is already present

how to put a unique constraint on column if duplicate data is already present in that column?

Hello,
I have Oracle 10g and in this version documentation (SQL Reference) just says
ENABLE NOVALIDATE ensures that all new DML operations on the constrained data comply with the constraint. This clause does not ensure that existing data in the table complies with the constraint and therefore does not require a table lock.
So, as far as I understand, it does not guarantee that the constraint is really not validated:
Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
Connected as xxxx
SQL>
SQL> create table drop_me as
  2  select 1 as id from dual
  3  union all
  4  select 1 as id from dual;
Table created
SQL> alter table drop_me
  2  add constraint unq_id unique (id) enable novalidate;
alter table drop_me
add constraint unq_id unique (id) enable novalidate
ORA-02299: cannot validate (XXXX.UNQ_ID) - duplicate keys found
SQL>

Similar Messages

  • Unique constraint on valid_to and valid_from dates

    Suppose I have a table:
    create table test (name varchar2(40), valid_from date, valid_to date);
    insert into test values ('fred', to_date('01/04/2008', 'dd/mm/yyyy'), to_date('01/04/2008', 'dd/mm/yyyy');
    insert into test values ('fred', to_date('04/04/2008', 'dd/mm/yyyy'), to_date('06/04/2008', 'dd/mm/yyyy');
    insert into test values ('fred', to_date('08/04/2008', 'dd/mm/yyyy'), to_date('09/04/2008', 'dd/mm/yyyy');How can I enforce uniqueness such that at any one point in time, only one row exists in the table for each name?
    eg. insert into test values ('fred', to_date('02/04/2008', 'dd/mm/yyyy'), to_date('03/04/2008', 'dd/mm/yyyy'); -- success!
    insert into test values ('fred', to_date('02/04/2008', 'dd/mm/yyyy'), to_date('05/04/2008', 'dd/mm/yyyy'); -- fail!
    insert into test values ('fred', to_date('01/04/2008', 'dd/mm/yyyy'), to_date('03/04/2008', 'dd/mm/yyyy'); -- fail!
    insert into test values ('fred', to_date('05/04/2008', 'dd/mm/yyyy'), to_date('05/04/2008', 'dd/mm/yyyy'); -- fail!
    insert into test values ('fred', to_date('07/04/2008', 'dd/mm/yyyy'), to_date('11/04/2008', 'dd/mm/yyyy'); -- fail!Is there a method using fbi's or unique constraints? I'd really rather avoid using triggers and pl/sql if I can, but I can't think of a way...
    Message was edited by:
    Boneist
    Added some extra test conditions

    How about this pair of indexes:
    CREATE UNIQUE INDEX test_fromdate_idx ON test(name,valid_from);
    CREATE UNIQUE INDEX test_todate_idx ON test(name,valid_to);Here is the test:
    SQL> create table test (name varchar2(40), valid_from date, valid_to date);
    Table created.
    SQL> insert into test values ('fred', to_date('01/04/2008', 'dd/mm/yyyy'), to_date('01/04/2008', 'dd/mm/yyyy'));
    1 row created.
    SQL> insert into test values ('fred', to_date('04/04/2008', 'dd/mm/yyyy'), to_date('06/04/2008', 'dd/mm/yyyy'));
    1 row created.
    SQL> insert into test values ('fred', to_date('08/04/2008', 'dd/mm/yyyy'), to_date('09/04/2008', 'dd/mm/yyyy'));
    1 row created.
    SQL> CREATE UNIQUE INDEX test_fromdate_idx ON test(name,valid_from);
    Index created.
    SQL> CREATE UNIQUE INDEX test_todate_idx ON test(name,valid_to);
    Index created.
    SQL> insert into test values ('fred', to_date('02/04/2008', 'dd/mm/yyyy'), to_date('03/04/2008', 'dd/mm/yyyy'));
    1 row created.
    SQL> insert into test values ('fred', to_date('02/04/2008', 'dd/mm/yyyy'), to_date('05/04/2008', 'dd/mm/yyyy'));
    insert into test values ('fred', to_date('02/04/2008', 'dd/mm/yyyy'), to_date('05/04/2008', 'dd/mm/yyyy'))
    ERROR at line 1:
    ORA-00001: unique constraint (TEST_USER.TEST_FROMDATE_IDX) violated
    SQL> insert into test values ('fred', to_date('01/04/2008', 'dd/mm/yyyy'), to_date('03/04/2008', 'dd/mm/yyyy'));
    insert into test values ('fred', to_date('01/04/2008', 'dd/mm/yyyy'), to_date('03/04/2008', 'dd/mm/yyyy'))
    ERROR at line 1:
    ORA-00001: unique constraint (TEST_USER.TEST_FROMDATE_IDX) violated
    SQL> spool off;Hope this helps!

  • JPA uniqueness constraint on columns

    Hi all,
    I have a very simple data structure which has
    - the key (String) of another data class
    - a Date (using TemporalType.DATE)
    - an integer value
    but the combination of the timestamp and the key makes for a unique identifier. I could quite easily add an additional 4th @Column into my @Entity that is my @Id, but I'd rather investigate how JPA can help me setup a custom @Id that is the combination of the key and the timestamp value. It would be good to be able to let the database manage the uniqueness, instead of me having to programmatically handle (and check) it in JPA-QL queries.
    Is this a classic case of @EmbeddedId or @IdClass? If so, it seems like an awful lot of boilerplate code to achieve what I want. Is what I am proposing even recommended? Is there perhaps another way to achieve uniqueness for the combination of these two columns?

    In general I would recommend using a generated Id, but yes, your example is a case for using an @EmbeddedId or @IdClass.
    See,
    http://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing#Composite_Primary_Keys
    -- James : http://www.eclipselink.org

  • Coding challenge - Unique constraint between column in 2 different tables

    Hi I have 3 tables like
    project--> pk: projectid
    category --> pk: categoryid FK: projecid
    Buyer --> Pk: buyerid FK : Categoryid
    each project can have multiple categories, and each category can have multiple buyer. I need to ensure that a buyer can be adde to a project (uniqueness of projectid & Buyer id). I tried with triggers and its erroring out. Is there a easier way to enforce this?

    Selvaganapathy wrote:
    Hi I have 3 tables like
    project--> pk: projectid
    category --> pk: categoryid FK: projecid
    Buyer --> Pk: buyerid FK : Categoryid
    each project can have multiple categories, and each category can have multiple buyer. I need to ensure that a buyer can be adde to a project (uniqueness of projectid & Buyer id). I tried with triggers and its erroring out. Is there a easier way to enforce this?I think there is a logical error in the problem description.
    If one project can have multiple categories (P1 has C1 and C2) and one category can have multiple buyers (C1 has B1 and B2) then the project is automatically matched to two buyers (P1 has B1 and B2). This is against the rule project+buyer are unique.
    I think Selvaganapathy should explain the business logic with a practical example. my feeling is that the unuiqness is only on part of the buyer, not on part of the project. Like one Buyer can only be matched to one project, but one project can have several buyers. But this would allow totaly different solutions. Like adding the project ID to the Buyer table as a foreign key.
    Edited by: Sven W. on Aug 31, 2009 4:23 PM

  • Unique Constraint on CLOB XML

    From my research it appears you can't put a unique constraint on an xml record if the xml is stored as a CLOB. Could somebody confirm I am correct?
    If I'm wrong please provide an example on how do do it on the value attribute for the "key" node in following xml:
    <DomainObject className="Building" xmlns="hello world">
    <primitive value="1" name="key"/>
    <primitive value="111" name="jobId"/>
    <primitive value="1.0" name="height"/>
    </DomainObject>
    Thanks,
    Steve

    Since nobody responded I wung it. Even in schema based XML I don't think there is a way to put a unique constraint on the column in the way I needed it, so I wrote a BEFORE INSERT trigger which makes sure the key being inserted doesn't duplicate a key already in the table.
    Steve

  • Named column title duplicates in all??

    New to Numbers and wanting to put different headings for my columns, eg name, date etc. The value I type in the first column duplicates in each of the others - how can I name them individually please?

    Switchblade wrote:
    New to Numbers and wanting to put different headings for my columns, eg name, date etc. The value I type in the first column duplicates in each of the others - how can I name them individually please?
    Which Numbers version are you running.
    What you describe ids the behaviour of Numbers '08 when we enter a formula in an header.
    It's my dear old friend : "Applying a Formula Once to Cells in a Column or Row"
    Yvan KOENIG (VALLAURIS, France) dimanche 11 avril 2010 14:32:44

  • Unique constraint is not thrown when used MERGE INSERT (alone) via dblink.

    We found some interesting behaviour of unique constraint on Merge query when we use Merge When Not Matched Insert (no update query) via a dblink.
    In one Schema S1, on Table A1(c1,c2,c3) there is a unique constraint on column (c1,c2).
    Column c2 is nullable and has null for some records.
    Now i have a table A2 with same defintion as A1 in Schema S2.In S2 , i have a dblink of S1 as S1 itself.
    I have data in S2.A2. Here also i have some records with c2 as null and c1 matching with the data of S1.A1.
    Now from schema S2,
    I am using the following Merge Query,
    MERGE INTO S1.A1 target
    USING S2.A2 source
    ON (target.c1 = source.c1 and target.c2 = source.c2)
    WHEN NOT MATCHED
    INSERT (c1,c2,c3) values (source.c1, source.c2,source.c3)
    WHEN MATCHED
    UPDATE c3 = source.c3;
    Now when i execute this merge in schema S2,
    if i have some data in S1.A1 and S2.A2 having c1 as same and c2 as null, as oracle does not treat two nulls same, it goes for an insert, i have got unique constraint violated error.
    But if i execute MERGE INSERT alone, though that record is getting inserted , i am not getting unique constraint violated error.
    Oracle version we are using is 10g (10.2...).
    Is it a bug in oracle or what could have caused this behaviour.

    Dear,
    ERROR at line 1:
    ORA-00001: unique constraint (SYS_C00137508) violatedYou need to think about two things
    (a) read consistency : what was the situation of table_1 when the maching clause has been initially evaluated ; there were 0 rows matching which means the merge operation will be all insert
    (b) your matching clause has a problem : the join column must be unique in both tables otherwise the merge will be ambigous. You don't have a unique key on the source table
    (c) think that the merge operation will never insert id =1 and then update id = 1 within the same operation. This will never happen
    Hope this helps
    Mohamed Houri

  • Mapping failed due to Unique Constraint

    Hi,
    We are using Oracle Financial Analytics and noticed that one of the mapping SIL_PositionDimenstionHierarchy failed due to Unique Constraint.
    Mapping was inserting data into W_POSITION_DH table.
    Is there a way to find the source table from where it is inserting the record?
    I don't have much Informatica experience.
    Thanks,
    Poojak

    Hi,
    Our servers are hosted to Oracle On Demand. I have opened a ticket with Oracle. They have asked us to aply a patch to increase the version of the Mapping.
    Please see update from Analyst.
    "Development team is requesting to apply patch number 9782718, which solves this issue as well.
    You need to go to Patches and Updates tab on Support Portal, click on Oracle, Siebel and Hyperion products link and do a simple search with patch number 9782718. The patch files contain detailed instructions.
    Please test on your Test environment first before applying to Production. Let us know if you have any issues.
    Thanks,
    Poojak

  • Performance Impact of Unique Constraint on a Date Column

    In a table I have a compound unique constraint which extends over 3 columns. As a part of functionality I need to add another DATE column to this unique constraint.
    I would like to know the performance implications of adding a DATE column to the unique constraint. Would the DATE column behave like another VARCHAR2 or NUMBER column, or would it degrade the performance significantly?
    Thanks
    Message was edited by:
    user627808

    What performance are you concerned about degrading? Inserts? Or queries? If you're talking about queries, what sort of access path are you concerned about?
    Are you concerned that merely changing the definition of the unique constraint would impact performance? Or are you worried that whatever functional change you are making would impact performance (i.e. if you are now retaining historical data in the table rather than just updating it)?
    Regardless of the performance impact, unique indexes (and unique constraints) need to be correct. If you need to allow duplicates on the 3 current columns with different dates, then you would need to change the unique constraint definition regardless of the performance impact. Fast and wrong generally isn't going to be preferrable to slow and right.
    Generally, though, there probably is no reason to be terribly concerned about performance here. Indexing a date is no different than indexing any other primitive data type.
    Justin

  • HOWTO: Add a UNIQUE constraint to a populated column

    Here is the way to add a unique constraint to a populated column, ensuring that the existing values are unique as well.
    ALTER TABLE t1
    ADD CONSTRAINT t1_uk UNIQUE (col1,col2)
    EXCEPTIONS INTO my_exceptions
    /If the alter table statement fails this will populate the MY_EXCEPTIONS table with the rows that contain duplicate values for (col1,col2). These are identified by ROWID. We can then chose to:
    [list]
    [*]delete rows with a bad key;
    [*]amend the values of the key columns;
    [*]re-apply the constraint with the NOVALIDATE option.
    [list]
    We should be wary of choosing the NOVALIDATE option. There's usually a good reason why the unique constraint is required and we should not circumvent it. Apart from anything else, Oracle allows us to build foreign keys referencing NOVALIDATE unique keys. This could result in child rows that have two parents, which is normal in biology, but very wrong in a database.
    NOVALIDATE is useful in datawarehouses and suchlike, because little updating occurs and the data integrity issues are of less imporatance. I don't think it ought to be used in OLTP situations. The code example at the end of this posting illustrates why we should exercise caution with NOVALIDATE.
    Once we have handled the duplicate values we can re-run the alter table statement and apply the constraint.
    If you don't already have an EXCEPTIONS table (it can be called anything, it's the structure that counts) you may need to run (or get a DBA to run) a script called UTLEXCPT.SQL, which will be in the $ORACLE_HOME/rdbms/admin directory.
    Cheers, APC
    SQL> SELECT col1, col2, col3 FROM t1;
          COL1       COL2       COL3                                               
             1          1          0                                               
             2          1          0                                               
             2          1          0                                               
    SQL> SELECT col1, col2, cola FROM t2;
          COL1       COL2 COLA                                                     
             1          1  I'm child #1                                                        
             1          1  I'm child #2                                                        
             2          1  I'm child #3                                                        
    SQL> ALTER TABLE t1
      2  ADD CONSTRAINT t1_uk UNIQUE (col1, col2);
    ALTER TABLE t1 ADD CONSTRAINT t1_uk UNIQUE (col1, col2)
    ERROR at line 1:
    ORA-02299: cannot validate (TST2.T1_UK) - duplicate keys found We can't add a unique key, so we decide to use the NOVALIDATE clause.
    SQL> CREATE INDEX t1_i ON t1(col1, col2);
    Index created.
    SQL> ALTER TABLE t1
      2  ADD CONSTRAINT t1_uk UNIQUE (col1, col2) ENABLE NOVALIDATE;
    Table altered.
    SQL> INSERT INTO t1 VALUES (2, 1, 1);
    insert into t1 values (2, 1, 1)
    ERROR at line 1:
    ORA-00001: unique constraint (TST2.T1_UK) violated Well, we can't add any more duplicate keys, so that's alright isn't it? Nope. We can add a foreign key to table T2 referencing T1 but we don't know which row in T1 is the parent of the rows in T2.
    SQL> ALTER TABLE t2
      2  ADD CONSTRAINT t2_t1_fk foreign key  (col1, col2)
      3  REFERENCES t1(col1, col2)
    Table altered.
    SQL> SELECT rowid FROM t1 WHERE col1 = 2;
    ROWID                                                                          
    AAAVnMAANAAAB96AAB                                                             
    AAAVnMAANAAAB96AAC                                                             
    SQL> DELETE FROM t1 WHERE rowid = 'AAAVnMAANAAAB96AAB';
    1 row deleted.
    SQL> DELETE FROM t1 WHERE rowid = 'AAAVnMAANAAAB96AAC';
    DELETE FROM t1 WHERE rowid = 'AAAVnMAANAAAB96AAC'
    ERROR at line 1:
    ORA-02292: integrity CONSTRAINT (TST2.T2_T1_FK) violated - child record found
    SQL> ROLL
    Rollback complete.
    SQL> DELETE FROM t1 WHERE rowid = 'AAAVnMAANAAAB96AAC';
    1 row deleted.
    SQL> DELETE FROM t1 WHERE rowid = 'AAAVnMAANAAAB96AAB';
    DELETE FROM t1 WHERE rowid = 'AAAVnMAANAAAB96AAB'
    ERROR at line 1:
    ORA-02292: integrity CONSTRAINT (TST2.T2_T1_FK) violated - child record found
    SQL>  ROLL
    Rollback complete.
    Why this matters: queries joining child and parent tables return more rows than we'd expect normally.
    SQL> SELECT t2.cola
      2  FROM   t2
      3  WHERE  t2.col1 = 2
      4  and    t2.col2 = 1;
    COLA                                                                           
    I'm child #3                                                                   
    SQL> SELECT t2.cola, t1.col4
      2  FROM   t1, t2
      3  WHERE  t2.col1 = 2
      4  AND    t2.col2 = 1
      5  AND    t1.col1 = 2
      6  AND    t2.col2 = 1;
    COLA                    COL4                                                   
    I'm child #3            I'm the daddy                                          
    I'm child #3            No, I'm the daddy!!                                    
    SQL> Caveat emptor
    This posting is issued on behalf of the Rogue Moderators. It is posted with the best of intentions but is not guaranteed in any way, shape or form. In particular, the code is presented "as is" and you assume full responsibility for running it on your system. Furthermore, you must not download and install software from the internet unless you know what you are doing and have the permission of whoever owns your system. It was never this hard for the Lone Ranger.

    Hi,
    You can not create unique key with duplicate values as you know. Now if you want to create unique key then you have to delete duplicate records from the table but this again if you can afford to delete because this data may be more importante to you and you can not delete any record.
    or you can use ENABLE NOVALIDATE option of oracle explain by Tom on below link.
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:8806498660292
    or if you dont want to use Tom's way then you go with primary key like
    Drop old primary key if there is already on the column.
    create new primary key with enable novalidate option.

  • Unique constraint violation while updating a non PK column

    Hi,
    I seem to have found this strange error.
    What I try to do is bulk fetch a cursor in some table arrays. with limit of 1000
    Then using a forall and a save exceptions at the end
    I update a table with the values inside one of the table arrays.
    The column I update is not part of a PK
    I catch the error message: ORA-24381
    by using PRAGMA exception_init(dml_errors, -24381);
    and later on :
    WHEN dml_errors THEN
    errors := SQL%BULK_EXCEPTIONS.COUNT;
    FOR i IN 1..sql%BULK_EXCEPTIONS.count LOOP
    lr_logging.parameters:= 'index = ' || sql%BULK_EXCEPTIONS(i).error_index || 'error = ' ||Sqlerrm(-sql%BULK_EXCEPTIONS(i).error_code) ;
    END LOOP;
    I insert these errors in another table. and i get 956 errors
    first one is :
    index = 3error = ORA-00001: unique constraint (.) violated
    last one is
    index = 1000error = ORA-00001: unique constraint (.) violated
    How can this be.Since i don't update in a PKcolumn.
    FULL CODE IS:
    PROCEDURE Update_corr_values( as_checkdate_from IN VARCHAR2,
    as_checkdate_until IN VARCHAR2,
    as_market IN VARCHAR2
    IS
    LS_MODULE_NAME CONSTANT VARCHAR2(30) := 'update_values';
    lr_logging recon_logging.logrec;
    CURSOR lc_update IS
    SELECT /*+ORDERED*/c.rowid,c.ralve_record_id,d.value,c.timestamp,f.value
    FROM rcx_allocated_values a,
    rcx_allocated_values b,
    meter_histories e,
    rcx_allocated_lp_value c,
    rcx_allocated_lp_value d,
    counter_values f
    WHERE a.slp_type NOT IN ('S89', 'S88', 'S10', 'S30') --AELP
    AND b.slp_type IN ('S89', 'S88') --residu
    AND a.valid_from >= to_date(as_checkdate_from,'DDMMYYYY HH24:MI')
    AND a.valid_to <= to_date(as_checkdate_until,'DDMMYYYY HH24:MI')
    AND a.market = as_market
    AND a.market = b.market
    AND a.ean_sup = b.ean_sup
    AND a.ean_br = b.ean_br
    AND a.ean_gos = b.ean_gos
    AND a.ean_dgo = b.ean_dgo
    AND a.direction = b.direction
    AND a.valid_from = b.valid_from
    AND a.valid_to = b.valid_to
    AND c.ralve_record_id = a.record_id
    AND d.ralve_record_id = b.record_id
    AND c.TIMESTAMP = d.TIMESTAMP
    AND e.ASSET_ID = 'KCF.SLP.' || a.SLP_TYPE
    --AND f.timestamp between to_date(gs_checkdate_from,'ddmmyyyy') and to_Date(as_checkdate_until,'ddmmyyyy')
    AND e.SEQ = f.MHY_SEQ
    AND f.TIMESTAMP =c.timestamp - 1/24
    ORDER BY c.rowid;
    TYPE t_value IS TABLE OF RCX_ALLOCATED_LP_VALUE.VALUE%TYPE;
    TYPE t_kcf IS TABLE OF COUNTER_VALUES.VALUE%TYPE;
    TYPE t_timestamp IS TABLE OF RCX_ALLOCATED_LP_VALUE.TIMESTAMP%TYPE;
    TYPE t_ralverecord_id IS TABLE OF RCX_ALLOCATED_LP_VALUE.RALVE_RECORD_ID%TYPE;
    TYPE t_row IS TABLE OF UROWID;
    ln_row t_row :=t_row();
    lt_value t_value := t_Value();
    lt_kcf t_kcf := t_kcf();
    lt_timestamp t_timestamp := t_timestamp();
    lt_ralve t_ralverecord_id := t_ralverecord_id();
    v_bulk NUMBER := 1000;
    val number;
    kcf number;
    ralve number;
    times date;
    dml_errors EXCEPTION;
    errors NUMBER;
    PRAGMA exception_init(dml_errors, -24381);
    BEGIN
    --setting arguments for the logging record
    lr_logging.module := LS_MODULE_NAME;
    lr_logging.context := 'INFLOW_ALL_VALUES_PARTS';
    lr_logging.logged_by := USER;
    lr_logging.parameters := 'Date time started: ' || TO_CHAR(sysdate,'DD/MM/YYYY HH24:MI');
    -- log debugs
    recon_logging.set_logging_env (TRUE, TRUE);
    recon_logging.log_event(lr_logging,'D');
    OPEN lc_update;
    LOOP
    FETCH lc_update BULK COLLECT INTO ln_row,lt_ralve,lt_value,lt_timestamp,lt_kcf LIMIT v_bulk;
    FORALL i IN NVL(lt_value.first,1)..NVL(lt_value.last,0) SAVE EXCEPTIONS
    UPDATE RCX_ALLOCATED_LP_VALUE
    SET VALUE = VALUE * lt_value(i) * lt_kcf(i)
    WHERE rowid =ln_row(i);
    COMMIT;
    lt_value.delete;
    lt_timestamp.delete;
    lt_ralve.delete;
    lt_kcf.delete;
    ln_row.delete;
    EXIT WHEN lc_update%NOTFOUND;
    END LOOP;
    CLOSE lc_update;
    recon_logging.log_event(lr_logging,'D');
    lr_logging.parameters := 'Date time ended: ' || TO_CHAR(sysdate,'DD/MM/YYYY HH24:MI');
    recon_logging.log_event(lr_logging,'D');
    --to be sure
    COMMIT;
    EXCEPTION
    WHEN dml_errors THEN
    recon_logging.set_logging_env(TRUE,TRUE);
    lr_logging.module := 'updatevalues';
    lr_logging.context := 'exception';
    lr_logging.logged_by := USER;
    lr_logging.parameters := 'in dml_errors';
    recon_logging.log_event(lr_logging);
    errors := SQL%BULK_EXCEPTIONS.COUNT;
    lr_logging.parameters:=errors;
    recon_logging.log_event(lr_logging);
    lr_logging.parameters :=('Number of errors is ' || errors);
    --DBMS_OUTPUT.PUT_LINE('Number of errors is ' || errors);
    FOR i IN 1..sql%BULK_EXCEPTIONS.count LOOP
    lr_logging.parameters:= 'index = ' || sql%BULK_EXCEPTIONS(i).error_index || 'error = ' ||Sqlerrm(-sql%BULK_EXCEPTIONS(i).error_code) ;
    recon_logging.log_event(lr_logging);
    END LOOP;
    --recon_logging.set_logging_env(TRUE,TRUE);
    --recon_logging.log_event(lr_logging);
    commit;
    WHEN OTHERS THEN
    lr_logging.module := 'updatevalues';
    lr_logging.context := 'exception';
    lr_logging.logged_by := USER;
    recon_logging.set_logging_env(TRUE,TRUE);
    lr_logging.parameters := 'in others error=' || SQLERRM;
    recon_logging.log_event(lr_logging);
    commit;--to look which is truly the last (else only commit after 1000)
    --raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
    END Update_corr_values;

    Hi,
    No I didn't update a unique constraint.
    But I found out that there is a trigger that causes the unique constraint while updating in the table.
    Silly mistake.Didn't know there was a trigger there.
    Thx anyway.
    Greetz

  • How to create unique constraint on a col which has duplicate values

    Hi all,
    how can i create a unique constraint on a field which have duplicate vaules with no validate clause.
    My table name is "ACCT"
    Regards
    Message was edited by:
    53637

    Check out following
    SQL>DROP TABLE TEST;
    Table dropped.
    SQL>CREATE TABLE TEST
      2  (
      3     ID          NUMBER
      4    ,NAME        VARCHAR2(30)
      5    ,CITY        VARCHAR2(30)
      6  );
    Table created.
    SQL>INSERT INTO TEST VALUES(1,'Rajesh','Gurgaon');
    1 row created.
    SQL>INSERT INTO TEST VALUES(1,'Rajesh','Gurgaon');
    1 row created.
    SQL>INSERT INTO TEST VALUES(2,'Dinesh','Delhi');
    1 row created.
    SQL>INSERT INTO TEST VALUES(1,'Rajan','Pune');
    1 row created.
    SQL>INSERT INTO TEST VALUES(1,'Rajan','Pune');
    1 row created.
    SQL>COMMIT;
    Commit complete.
    SQL>ALTER TABLE test ADD CONSTRAINTS uk_on_test UNIQUE(ID,NAME,CITY) DEFERRABLE NOVALIDATE ;
    Table altered.
    SQL>ALTER TABLE test
      2  ENABLE NOVALIDATE CONSTRAINT uk_on_test;
    Table altered.
    SQL>INSERT INTO TEST VALUES(1,'Rajesh','Gurgaon');
    INSERT INTO TEST VALUES(1,'Rajesh','Gurgaon')
    ERROR at line 1:
    ORA-00001: unique constraint (AIP.UK_ON_TEST) violatedRegards
    Arun

  • UNIQUE constraint on a varchar column

    I have a (non-key) varchar2 column that I need to be unique. I specify UNIQUE in the table create line like:
    create table tester(
    id number primary key,
    field varchar2(255) UNIQUE
    but it doesn't behave as expected. The following statements don't cause a constraint violation:
    insert into tester values(1,'text');
    insert into tester values(2,'tEXT');
    That is, UNIQUE on a varchar column is case sensitive. How can I create a case-insensitive UNIQUE constraint?
    null

    Take a look at the 'new' feature named function based indexes. I do not now if you can create a unique this way but at least you can try. Keep us informed please.

  • ORA-00001 - Unique Constraint error in Oracle forms 6i

    Hi,
    I am using Forms 6i. I have an issue while inserting records into a custom table.  Below is the functionality.
    When I check the check box,  and press the 'APPROVE' button, the record gets inserted into the custom table. But while inserting I am getting 'ora-00001-unique constraint violated error'.
    But the custom table doesn't have any data in it. (So the inserting record should not be a duplicate record).
    Any suggestions would be of great help.
    Thanks
    Deepti

    Is it a sql statement that is performing the insert, or are you using the native data block DML functionality in your form?  Secondly have you identified candidate columns that could be causing your issue?
    If you are using sql statement have you debugged to comfirm that you are not firing the same block of code more that once, and that if it is required to execute multiple times are you incrementing the sequence values that should be unique.
    Regards
    Q

  • MView refresh error on 10gR2..(unique constraint error)

    Hi. all.
    The database is 2-node RAC 10gR2 on SunOS.
    Today morining, I got the following error.
    EXEC dbms_refresh.refresh('"ODSFAB"."CURRENTWIP"');
    ORA-12008: error in materialized view refresh path
    ORA-00001: unique constraint (ODSFAB.CURRENTWIP_GLASS_IDX) violated
    ORA-06512: at "SYS.DBMS_SNAPSHOT", line 2254
    ORA-06512: at "SYS.DBMS_SNAPSHOT", line 2460
    ORA-06512: at "SYS.DBMS_IREFRESH", line 683
    ORA-06512: at "SYS.DBMS_REFRESH", line 195
    ORA-06512: at line 1
    I checked both the source and target table, but there is no unique-key confliction.
    The source table has no unique index, but the target table have one unique index
    for a business purpose.
    Finally, I dropped the miew log on a source table and mview , and recreated mview
    log and mview with the same unique constraint and the same data.
    I do not understand why I got "Unique constraint error".
    Any advice will be welcomed.
    Thanks in advance.
    Have a good day.
    Best Regards.
    Message was edited by:
    user507290

    Let us say column A is the unique key on target DB and exists in source DB.
    Now, on source DB,
    - Value 'X' is inserted in col A
    - Value "X" is again inserted in col A (or updated on colA)
    - Then one of these 2 rows is deleted
    Now, "if" Oracle applies all the transactions from the source to target in the
    same sequence as they occured, there is chance you can get unique error.you do
    But, if a full refresh, there won't be error.I would say that is a very plausible explanation. Somewhat difficult to verify, in the absence of low-level auditing on the source database.
    The situation as described is a bit yucky. Is there no way of putting a unique key on the table in the source database? If not, it seems to me that this scenario is bound to re-occur.
    Cheers, APC
    Blog : http://radiofreetooting.blogspot.com/

Maybe you are looking for

  • How to restrict Cut, Copy and Paste to a Local Clipboard.

    I need to stop any information being copied from my application to other applications such as Word. Is there any way to make sure that all GUI components that support cut, copy and paste use a local clipboard so that I can then control which Flavor's

  • 3 weeks service time?

    Hi all, I sent my  3 months old iphone 5 back to a Vodafone shop where I got it, they request 2 to 3 weeks service time, is this normal and standard? Now that we all got used to a smart phone companion 24/7 for 1001 daily help! No  push emails, no in

  • Design question on using PL/SQL table

    Hi I am doing some data extract and write it to a file. The main table is over 100 million rows. It is is partition by ID. So I am thinking of paralleling it. We are on 10g so we can not use the dbms_parallel. I would like to use dbms_scheduler or th

  • Unicode check in 4.6C

    Hi All , Is there any way to have the unicode check feature i.e.UCCHECK in R/3 4.6C environment ? please let me know if anyone has any clue. Regards Yogesh

  • Snippets in Dreamweaver CS3

    Hello, I am wanting to use some of the snippets provided with Dreamweaver CS3. However I can not find info on how to make the scripts actually work. Are there available tutorials on this? I have found nothing in the "help" documentation. Thanks.