Unique constraint on the values in both directions

I'm looking to create a unique constraint that works in two ways. Say I got a constraint unique in columns 1 and 2. I want it to be impossible for the two lines below the two exist at the same time. Is there a way to do this? I googled around for a while now and I found nothing that works so far.

Header 1 Header 2
DogCAT
CATDog

Hello

You can create an index based on a single function:, like this:

CREATE UNIQUE INDEX table_x_header_1_header_2

ON table_x (LESS (header_1, header_2)

More LARGE (header_1, header_2)

);

How will you use these values?  You might be better to simply create a regular old unique constraint, but also have a CHECK constraint to ensure that header_1<= header_2. ="" that="" way,="" when="" you="" want="" to="" search="" for="" the="" combination="" ('cat',="" 'dog')="" you="" won't="" have="" to="" search="" for="" ('dog',="" 'cat')="">

Tags: Database

Similar Questions

  • 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

  • Unique constraint in the form of master detail error

    Hi all

    I need help, the following requirement.

    I have a master detail form developed on master-child table. the tables have the composite key.

    Old masters has a composite key on columns (A, B)

    Children table has a composite key on columns (A, B, C)

    Child block look something like below

    C       A          B

    10 AAA 1000

    20 1300 BBB

    30 CCC 1400

    40 DDD 1200

    Increments of column C with 10 for each record, and if a new record is insert in intermediaries the records it is incremented to 5.

    My requirement is when an end user attempts to insert record between 20 and 30 or 30 and 40 and clicks on save, the value of the C column must regenerate as shown below

    C       A          B

    10 AAA 1000

    20 1300 BBB

    XXX 30 900

    40 CCC 1400

    50 DDD 1200

    Button Save I wrote the following code

    Declare
      ln_Count NUMBER :=0;
      ln_c number :=0
      cursor c1 is
      select c
      from child
      where a=:child.a
      and b=:child.b
    Begin
      Go_Block('Child');
      First_Record;
      LOOP
      ln_Count:= ln_Count+10;
      :child.C := ln_Count;
      EXIT When :System.Last_Record = 'TRUE';
      Next_Record;
      END LOOP;
    
    
      For c_cur in c1 Loop
      update child
      set c:=ln_c+10
      where a=:child.a
      and b=:child.b 
      and c=c_cur.c
      end loop;
      Forms_DDL('commit');
         
         commit_prc('Commit');  -- We have our own program unit to call commit_form
    
    END;
    

    I tried above in a way because, before approving the changes to the table, I update the existing values in the table of the C column so I would not get unique constraint error.

    When you click the button Save, I get a constraint exception. Hope I made my requirement clear.

    Can someone give me a clue to this implementation.

    Thank you

    malandain

    With this update, all your C-columnvalue became negative. When you post the form thereafter, forms update agaion records one by one the new positive figures. Because the numbers of 'old' in the db are now negative, there will be no violation-UK.

  • a unique index or unique constraint on the issue of view Matt

    10.2.0.3

    I have an OLTP table and a matte view to fast refresh of the table in the warehouse. I have unique indexes on the matte view just as I have on the OLTP table. Of course, it's a bad idea because the updating Oracle on mattress views mechanism does not apply to the dml in the same order that it occurred on the side of OLTP? Should I get rid of all the unique indexes on views mattress in my warehouse and create regular index because of their unique nature will just happen because the side OLTP has a unique index? What will be the impact on the performance of the queries? Here's the alert log...

    Journal of owp2 alerts
    =======================
    ORA-12012: error on auto work 1595
    ORA-12008: error path refresh materialized view
    ORA-00001: unique constraint (SMS_AR. IU02_ROUTE_REF_MRKR) violated
    ORA-06512: at "SYS." DBMS_SNAPSHOT", line 510
    ORA-06512: at line 1
    ORA-00001: unique constraint (SMS_AR. IU02_ROUTE_REF_MRKR) violated
    ORA-00610: internal error Code
    ORA-12012: error on auto work 260282
    ORA-30439: updating of the ' ORA-30439: updating of the 'SMS_AR MV_ROUTE_REF_MRKR' failed due to the ORA-12008: error in the path of refresh materialized view
    ORA-00001: unique constraint (SMS_AR. IU02_ROUTE_REF_MRKR) violated
    ORA-06512: at "SYS." DBMS_SNAPSHOT", line 2254
    ORA-06512: at "SYS." DBMS_SNAPSHOT", line 2460
    ORA-06512: at "SYS." DBMS_SNAPSHOT", line 2429
    ORA-06512: at "SMS_AR.PA_PIES_WAREHOUSE", line 44
    ORA-06512: at line 2
    ORA-20000: index 'SMS_AR '. "' I01_MV_PIES_INV_REFMKR ' or the partition of this index is unusable

    Mark Reichman wrote:
    I think that this problem is resolved... Unless someone has something else to add. I have not tried yet... But it seems to be valid. I did a test and a unique constraint can be delayed in fact creates a non-unique index. So I need to remove my unique index on my matte view and create unique constraints can be delayed.

    Or...

    forget the unqiue part and simply change the indexes not unique because the main table has a unique index and guarantees uniqueness for me and the matte view will simply copy whats in the main table.

    Mark,

    the solution seems reasonable. Just a note: If you use a "reportable" unique constraint Oracle ignores any attempt to perform a direct-path insert of access and still stations conventional insert generating undo and many more again.

    As long as you do only a 'rapid' refresh, it should not matter, but in case you deal with refreshs full large MVs, this could make a difference when running not atomic refreshs (who can take advantage of the direct-path inserts / DML etc. at the same time)...

    Then you can consider using only non-unique index rather than the constraint may be delayed if performance can matter and given the fact that you should never see duplicates in the MV because of the constraint on the base table.

    Furthermore, you can use a non-unique index to apply a not reportable unique/primary key constraint as well, it is supported. You just need to create the index yourself before you set the constraint or using explicit syntax "CREATE INDEX" of the constraint clause.

    For more information, I wrote a note on this problem "may be deferred" some time ago:

    http://Oracle-Randolf.blogspot.com/2008/07/Deferrable-constraints-and-direct-path.html

    Kind regards
    Randolf

    Oracle related blog stuff:
    http://Oracle-Randolf.blogspot.com/

    SQLTools ++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676 /.
    http://sourceforge.NET/projects/SQLT-pp/

  • Change the value of varying directly?

    Suppose I have a variant from an external source.

    Suppose I know the data type, but I don't know the attributes and their values (if any).

    Is it possible to directly change the value of the variant, "under the hood" so to speak and leave all attributes intact?

    I know that I can read all attributes, generate a new variant with my new data and write them all back, but that seems very inefficient.

    Casting of new data to a variant, and then using the variant of data to convert the Original variants type that seems to work as well. Once again, kludgy.

    Sting autour with «...» VI.lib\Utility\VariantDataType\*.*, but so far, not to find a method 'live '.

    Thank you!

    You can use the structure of the element inplace to set the value of a varying existing.  It retains all the existing attributes.

  • Unique constraint during the race error collecting statistics of schema

    Hello
    I get this error periodically during execution to collect statistics of schema
    In GATHER_SCHEMA_STATS , schema_name= ALL percent= 40 degree = 8 internal_flag= NOBACKUP
    Unable to correctly update the history table - fnd_stats_hist.
    -1 - ORA-00001: unique constraint (APPLSYS.FND_STATS_HIST_U1) violated
    Unable to correctly update the history table - fnd_stats_hist.
    -1 - ORA-00001: unique constraint (APPLSYS.FND_STATS_HIST_U1) violated
    Unable to correctly update the history table - fnd_stats_hist.
    -1 - ORA-00001: unique constraint (APPLSYS.FND_STATS_HIST_U1) violated
    Unable to correctly update the history table - fnd_stats_hist.
    -1 - ORA-00001: unique constraint (APPLSYS.FND_STATS_HIST_U1) violated
    Unable to correctly update the history table - fnd_stats_hist.
    -1 - ORA-00001: unique constraint (APPLSYS.FND_STATS_HIST_U1) violated
    Unable to correctly update the history table - fnd_stats_hist.
    -1 - ORA-00001: unique constraint (APPLSYS.FND_STATS_HIST_U1) violated
    Unable to correctly update the history table - fnd_stats_hist.
    -1 - ORA-00001: unique constraint (APPLSYS.FND_STATS_HIST_U1) violated
    Unable to correctly update the history table - fnd_stats_hist.
    -1 - ORA-00001: unique constraint (APPLSYS.FND_STATS_HIST_U1) violated
    Unable to correctly update the history table - fnd_stats_hist.
    -1 - ORA-00001: unique constraint (APPLSYS.FND_STATS_HIST_U1) violated
    Unable to correctly update the history table - fnd_stats_hist.
    -1 - ORA-00001: unique constraint (APPLSYS.FND_STATS_HIST_U1) violated
    Unable to correctly update the history table - fnd_stats_hist.
    -1 - ORA-00001: unique constraint (APPLSYS.FND_STATS_HIST_U1) violated
    I went thru notes 470556.1 , but I have not applied patch 5876047 according to the note.

    I can truncate table FND_STATS_HIST? Is it safe to truncate this table?

    Thank you
    ARS

    Published by: user7640966 on January 2, 2011 23:58

    Hi Ars;

    If I suggest his prod, make sure you have a valid backup of your system and also raise sr and confirm with oracle support. If you are on the clone or test, such as mention of doc first to backup table FND_STATS_HIST (make sure that you have a valid backup), truncate and repeat the test question

    Respect of
    HELIOS

  • Submit the page and pass the value in both

    Hi all

    I have a tabular presentation on the EMP table. The SQL property of the form is:

    SELECT empno, ename, sal
    WCP
    WHERE deptno =: P0_DEPTNO

    On the form, I have three buttons labeled as dept10, dept20 and dept30. I want to achieve the following when I press a button:

    1. send the page.
    2. value of: P0_DEPTNO is set according to the key pressed.

    I am able to perform only one of the above, at the same time. How can I achieve both at the same time.

    I use Oracle 10 g with Apex 4.0.

    Thank you
    Zahid

    In fact, it would be cleaner to create a single post submit PL/SQL process as follows:

    BEGIN
    :P0_DEPTNO := CASE :REQUEST
        WHEN 'dept10' THEN value_for_dept10 button
        WHEN 'dept20' THEN value_for_dept20 button
        WHEN 'dept30' THEN value_for_dept30 button
        END CASE;
    END;
    

    Or if you want the name of the button to P0_DEPTNO, then just

    :P0_DEPTNO  :=  :REQUEST;
    
  • How to select all the values populated both of LOV

    Hi all.

    I developed a form containing fields in a table. I join these areas a LOV (which get values in the other table). Now, I have to select a value only once for each record.
    But my question is how to map all the LOV values to these fields at a time. If it is possible what exactly is the way.
    If this is not possible then what is the way to do that.

    Thanks in advance

    Hello!
    Try using this code.
    You will get a lot of messages, but you can discover what column could not be red:

    declare
    l_group recordgroup := find_group ( 'lov27' );
    l_result pls_integer;
    begin
    if
      show_lov --> show the lov and user selected a value
    then
      l_result := populate_group ( l_group );
      clear_record;
      for i in 1..get_group_row_count ( l_group ) loop
        message ( 'reading  personal no' );
        :bill_detail.personal_no := get_group_char_cell ( 'lov27.personal_no', i );
        message ( 'reading  name' );
        :bill_detail.name := get_group_char_cell ( 'lov27.name', i );
        message ( 'reading  desigantion' );
        :bill_detail.designation := get_group_char_cell ( 'lov27.designation', i );
        message ( 'reading  rank' );
        :bill_detail.rank := get_group_char_cell ( 'lov27.rank', i );
        message ( 'reading  basic scale' );
        :bill_detail.basic_scale := get_group_number_cell ( 'lov27.basic_scale', i );
        message ( 'reading  basic pay' );
        :bill_detail.basic_pay := get_group_number_cell ( 'lov27.basic_pay', i );
        message ( 'reading  basic pay' );
        :bill_detail.vendor_no := get_group_number_cell ( 'lov27.vendor_no', i );
        message ( 'reading  branch code' );
        :bill_detail.branch_code := get_group_number_cell ( 'lov27.branch_code', i );
        message ( 'reading  sr no' );
        :bill_detail.sr_no := get_group_number_cell ( 'lov27.sr_no', i );
        create_record;
      end loop;
    first_record;
    end if;
    end;
    
  • 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.

  • Unique constraint violation error

    Hi all

    I have a procedure called - FHM_DASHBOARD_PROC which inserts data into a table called FHM_DASHBOARD_F retrieve records in multiple tables. However, for a particular type of record, these data are not inserted because of the Unique constraint violation

    the procedure is:
    create or replace
    PROCEDURE FHM_DASHBOARD_PROC AS
    
    DB_METRICS_CNT1Z number;
    --V_PODNAME varchar2(10);
    V_KI_CODE_DB_STATSZ varchar2(50);
    V_ERRORSTRING varchar2(100);
    
    --CURSOR PODNAME_CUR IS SELECT PODNAME,SHORTNAME FROM CRMODDEV.POD_DATA WHERE PODSTATUS_ID=1 AND PODTYPE_ID=1 ORDER BY PODNAME;
    
    
    -- DB STATS
    
    BEGIN 
    
      -- OPEN PODNAME_CUR;
        --   LOOP
          --   FETCH PODNAME_CUR INTO V_PODNAME,V_POD_SHORTNAME ;
            -- EXIT WHEN PODNAME_CUR%NOTFOUND;
    
               BEGIN
               
                     SELECT COUNT(*) INTO DB_METRICS_CNT1Z FROM FHM_DB_METRICS_F A, FHM_DB_D B where A.DBNAME=B.DBNAME and PODNAME=V_PODNAME AND DB_DATE=TRUNC(SYSDATE-1);
                               DBMS_OUTPUT.PUT_LINE('DB_METRICS_CNT1Z :'|| DB_METRICS_CNT1Z);
                               IF DB_METRICS_CNT1Z >0 THEN
                             
                        DBMS_OUTPUT.PUT_LINE('DB STATS');
                                  
                       INSERT INTO FHM_DASHBOARD_F(PODNAME,DASH_DATE,KI_CODE,KI_VALUE,KI_STATUS)
                                  
                          (SELECT PODNAME, DASH_DATE AS CU_DATE, KI.KI_CODE, NVL(PF.KI_VALUE,0), 
                                                                  CASE
                                                                   WHEN PF.KI_VALUE = ki.warning_threshold then 2
                        when PF.KI_VALUE=0 then 0
                        ELSE 1 
                        END  AS ALERT_STATUS
                        
                        FROM 
                        
                        (SELECT PODNAME,DB_DATE AS DASH_DATE,decode(a.stats_last_status,'SUCCEEDED',1,'FAILED',2,'STOPPED',2,NULL,0) KI_VALUE from  
                        FHM_DB_METRICS_F a,fhm_db_d b where a.dbname=b.dbname and podname='XYZ' and db_date=TRUNC(SYSDATE-1) and dbtype='OLTP')PF,
                        FHM_KEY_INDICATOR_D KI where PF.PODNAME=KI.POD_NAME AND KI.TIER_CODE=3 AND KI.KI_NAME='DB_STATS'
                        AND (PF.PODNAME,TRUNC(PF.DASH_DATE),KI.KI_CODE) NOT IN (SELECT PODNAME,DASH_DATE,KI_CODE FROM FHM_DASHBOARD_F)); 
                                 COMMIT;
                     
                             ELSE
                                    SELECT KI_CODE INTO V_KI_CODE_DB_STATSZ FROM FHM_KEY_INDICATOR_D WHERE POD_NAME=V_PODNAME AND KI_NAME='DB_STATS';
                                     DBMS_OUTPUT.PUT_LINE('V_KI_CODE_DB_STATSZ :'||V_KI_CODE_DB_STATSZ);
                                     INSERT INTO FHM_DASHBOARD_F(PODNAME,DASH_DATE,KI_CODE,KI_VALUE,KI_STATUS) VALUES(V_PODNAME,TRUNC(SYSDATE-1),V_KI_CODE_DB_STATSZ,0,0); 
                                     COMMIT; 
                                     
                             END IF;
                            
         EXCEPTION
                            WHEN OTHERS THEN
                            V_ERRORSTRING :='INSERT INTO FHM_DASHBOARD_F_ERROR_LOG(POD_NAME,KI_NAME,ERRORNO,ERRORMESSAGE,DATETIME) VALUES
                   ('''||V_PODNAME||''',''DB_STATS'','''||SQLCODE||''','''||SQLERRM||''',SYSDATE)';                         
                   EXECUTE IMMEDIATE  V_ERRORSTRING;
                            COMMIT;
              END;
    
          --END LOOP;
      --CLOSE PODNAME_CUR;
    
    
    END;
    
    
    END FHM_DASHBOARD_PROC;
    and the table where data integration is
    CREATE TABLE "CRMODDEV"."FHM_DASHBOARD_F"
      (
        "PODNAME" VARCHAR2(25 BYTE) NOT NULL ENABLE,
        "DASH_DATE" DATE,
        "KI_CODE"   NUMBER NOT NULL ENABLE,
        "KI_VALUE"  NUMBER,
        "KI_STATUS" NUMBER,
        CONSTRAINT "FHM_DASHBOARD_F_DATE_PK" PRIMARY KEY ("DASH_DATE", "PODNAME", "KI_CODE") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING COMPUTE STATISTICS STORAGE(INITIAL 4194304 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "CRMODDEV_IDX" ENABLE,
        CONSTRAINT "FHM_DASHBOARD_F_KI_CODE_FK" FOREIGN KEY ("KI_CODE") REFERENCES "CRMODDEV"."FHM_KEY_INDICATOR_D" ("KI_CODE") ENABLE
      )
      PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS NOLOGGING STORAGE
      (
        INITIAL 3145728 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
      )
      TABLESPACE "CRMODDEV_TBL" ENABLE ROW MOVEMENT ;
    the constraint primary key is FHM_DASHBOARD_F_DATE_PK and is on 3 columns of the table, DASH_DATE, PODNAME, KI_CODE



    And it's the query used in the procedure to insert the data into the table
    (SELECT  PODNAME, DASH_DATE AS CU_DATE, KI.KI_CODE, NVL(PF.KI_VALUE,0), 
                                   CASE
                                   WHEN PF.KI_VALUE = ki.warning_threshold then 2
    when PF.KI_VALUE=0 then 0
    ELSE 1 
    END  AS ALERT_STATUS
    From 
    (Select  Podname,Db_Date As Dash_Date,Decode(A.Stats_Last_Status,'SUCCEEDED',1,'FAILED',2,'STOPPED',2,Null,0) Ki_Value From  -- Added Distinct
    FHM_DB_METRICS_F a,fhm_db_d b where a.dbname=b.dbname and podname in ('XYZ') and db_date = TRUNC(SYSDATE-2) and dbtype='OLTP')PF,
    Fhm_Key_Indicator_D Ki Where Pf.Podname=Ki.Pod_Name And Ki.Tier_Code=3 And Ki.Ki_Name='DB_STATS'
    And (Pf.Podname,Trunc(Pf.Dash_Date),Ki.Ki_Code) Not In (Select Podname,Dash_Date,Ki_Code From Fhm_Dashboard_F));
    It gives * record * 2 suite
    ---------------------------------------
    XYZ JANUARY 20 12 2521 1 1
    XYZ JANUARY 20 12 2521 1 1

    It gives the Unique constraint violation error when inserting. Then, I changed in the above insertion code by adding a distinct clause. Once the query gives only a SINGLE record accordingly. However, this record is not be inserted into the table and give the same error.

    Now the question is how should I insert that record into the table with success?


    If the message is too long, however, I gave you the real structure of the object or procedure and error.

    Thank you in advance.

    When you have 5 columns in the game adding THAT SEPARATE is n ot solution that you can still get the same error once.

    Check the target table if the data exists before inserting... If this is not the case, check the structure of the table for a unique constraint created on other columns.

    select *from 
    where
    DASH_DATE=date '2012-01-20'
    and PODNAME='XYZ'
    and  KI_CODE=2521;
    
  • Programmatically change the name of the value axis on a second value axis

    Hello, I mixed graph signal on which I'm traced two signals.  I created a second value axis, while I have one left and right of the graph.  I am interested in the designation of the value on both axis and were able to appoint only the HR one by using the YScale.NameLbl.Text property.  How can I control the left side?

    Thank you!

    Hello

    You are in the right place, there is a property for this node, I think you should first set the scale is active, then set the property. Sorry I don't have the code I did it at hand for the moment.  It seemed that by using the node property of the top to the bottom, I have would be input to the axis, then change the properties, then another line of entry, change the properties and so on (I did x, but also two Y axis).

  • How can I create a constraint on the combination of four columns...

    Dear Guru,

    I have a question... I created the table with columns like "CCode', 'Size1', 'Size2', 'Sch1', 'Sch2', 'Description', 'CCdate '.

    Here I wanted to create a unique constraint on the combination of four columns "CCode', 'Size1', 'Size2', 'Sch1', 'Sch2.

    My requirement is that I don't want to allow duplicate records in the table for the four columns only.

    for example: "CC123", 10, 25, S110, S250,.

    If the new record comes with the same data. Then, I do not want to insert this record.i want to get a constraint voilated error.

    How can I create a constraint on the combination of four columns...

    Pls help me on this issue...

    Kind regards

    Shitab...

    I suggested already here the syntax,

    ALTER table your_table

    Add constraint cons_name unique (col1, col2, col3, col4, col5);

    And don't call me 'Sir '.

    See you soon!

  • Case-insensitive unique constraint

    Hi guys,.

    Is it possible to create a unique constraint that is case-insensitive

    I mean if there is a unique constraint on the name of col

    then
    'James' and 'JAMES' must not


    Kind regards

    PAPI

    Create a unique index to the basic function of...

    create unique index uk_name on emp(upper(ename));
    
  • Unique constraints

    I want to add a single validator to a feature attribute using 'list type of validator', the attribute is not the primary key.

    I'm following the userid not in userid viewobject.

    is this true?

    Hello Mohamed,

    to add a unique constraint on the entity object, you can add alternateKey "you can find it in the tab general entity ' of your entity attribute that you want to be unique and then adds unipue key validation 'entity level validation' and choose your secondary key created, then write failure management message

    Kind regards
    Karim Hasan

  • Unique constraint shot while refreshing in the MERGE statement.

    Hi guys

    I have a question that I can't solve. Would appreciate any help on this. The configuration of the data and the script is as below.
    SQL*Plus: Release 10.2.0.1.0 - Production on Wed May 4 11:46:02 2011
    
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    
    
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
    
    SQL> 
    
    create table table_1
    (id number,
     id_name varchar2(20));
     
    Alter table table_1 add primary key(id);
    
    create table table_2
    (id number,
     id_name varchar2(20));
     
     insert into table_2 values (1, 'id_1');
     insert into table_2 values (2, 'id_2');
     insert into table_2 values (1, 'id_1_upd');
    
    SQL> select * from table_1;
    
    no rows selected
    
    SQL> select * from table_2;
    
            ID ID_NAME
    ---------- --------------------
             1 id_1
             2 id_2
             1 id_1_upd
    
    SQL> 
    
    SQL>  merge into table_1 target
      2   using (select id, 
      3                 id_name
      4            from table_2) source
      5   on (source.id = target.id)
      6   when matched then
      7      update set target.id_name = source.id_name
      8   when not matched then
      9      insert(id,
     10             id_name)
     11      values(source.id,
     12             source.id_name);
     merge into table_1 target
    *
    ERROR at line 1:
    ORA-00001: unique constraint (SYS_C00137508) violated
    
    SQL> ed
    Wrote file afiedt.buf
    
      1  select constraint_type, table_name, status
      2*   from user_constraints where constraint_name = 'SYS_C00137508'
    SQL> /
    
    C TABLE_NAME                     STATUS
    - ------------------------------ --------
    P TABLE_1                        ENABLED
    Can someone help me please to solve this as the actual code that I am developing has the same configuration and I am constantly getting this error. As long as the same record does not come to the top in the 'source' table, MERGE performs an update or an insert.
    But as a "duplicate" coming soon to update, I get the error of unique constraint.

    Thank you
    -K.B.

    Dear Sir

    ERROR at line 1:
    ORA-00001: unique constraint (SYS_C00137508) violated
    

    You think two things

    (a) coherent reading: what was the situation of table_1 when the maching clause was initially assessed. There were 0 insert rows that correspond to which means that the merge operation will be all
    (b) your corresponding clause has a problem: the join column must be unique in both tables the case the merger will be ambiguous. You do not 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. Will never happen

    Hope this helps

    Mohamed Houri

Maybe you are looking for