How to Catch Unique Constraint in Exception

Hi,
I am writing a trigger TR_EMP on a table EMP which has columns EMP_ID, EMP_NAME, ALT_EMP_ID.
Now I am updating ALT_EMP_ID for an EMP_ID(PK) which is unique.
If ALT_EMP_ID is null
then
      :new.ALT_EMP_ID = l_alt_emp_id;
end if;As this ALT_EMP_ID is unique, same ID shouldn't be inserted again here. When data being inserted with 2 different sessions for 2 different EMP_ID there is a possible chance of inserting same ALT_EMP_ID for both which results in Unique error. I need to handle this exception. DUP_VAL_ON_INDEX or OTHERS Execption not able to handle this.
Can you help me out on how to handle such exception?

>
jeneesh wrote:
I am able to use dup_val_on_index
>
Can you please write an Exception for this query?
If ALT_EMP_ID is null
then     
      :new.ALT_EMP_ID = l_alt_emp_id;
end if;jeneesh wrote:
Moreover, what is your requirement? This design seems to be flawed. If you can explain teh actual requirement, forum members will be able to help you better..
>
Alternate Emp ID will be populated for Every employee. If on a same session when this ID is populated for 2 different Emplyoees then it will throw Unique constraint error, which should be handled.

Similar Messages

  • How to catch the user defined  exception in application service

    Hi All,
    How to catch the user defined  exception in application service  when it is throwed by the external service..
    Regards,
    Thirumurugan.

    Hi,
        Thanks for your reply,
            Actually I  am calling validate Login method of External service from the application service. When the login fails, my external service will throw user defined Exception.I want to catch the user defined Exception.
        But in the application service , validate Login method can catch  only Invocation Exception and Engine Exception.
       These two exception are present in the Application service remote interface.
      public com.sap.comptest.extsrv.accrjavawsvi__document.output.
    Ns1_validateLoginResponse validateLogin(com.sap.comptest.extsrv.accrjavawsvi__document.input.Ns1_validateLogin input) throws com.sap.caf.mp.base.exception.InvocationException, com.sap.caf.mp.base.exception.EngineException;
    User defined exception is not present there. When i include the webservice as external service in CAF, it suppossed to generate the java file for the custom exception of validate Login method and this generated file should be included in the application service remote interface..
    public com.sap.comptest.extsrv.accrjavawsvi__document.output.
    Ns1_validateLoginResponse validateLogin(com.sap.comptest.extsrv.accrjavawsvi__document.input.Ns1_validateLogin input) throws com.sap.caf.mp.base.exception.InvocationException, com.sap.caf.mp.base.exception.EngineException,
    (generated file name of user defined Excpetion.
      Then only  validate login method  of application service can catch  the user defined Exception which is thrown by the  external service.
    regards,
    Thirumurugan.p

  • How to handle ORA-00001: unique constraint in EXCEPTION block?

    Hi,
    Is there a specific exception thats raised when ORA-00001: unique constraint error occurs?

    SQL> create table test(id number primary key);
    Table created.
    SQL> set serverout on
    SQL> declare
      2   ex exception;
      3   pragma exception_init(ex,-1);
      4  begin
      5   insert into test values(1);
      6  exception
      7   when ex then
      8    dbms_output.put_line('dup');
      9   when others then
    10    raise;
    11  end;
    12  /
    dup                                                                            
    PL/SQL procedure successfully completed.
    <br>
    <a href ="http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/errors.htm#LNPLS00703">Predefied exceptions </a>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Catching unique constraint voilation at the VO level

    I have a Result table which is used as Result table/ for updation/ for insertion of new row.
    The underlying db table on which the Eo and consequently VO are based has a unique constraint which I want to catch and throw a suitable exception when the user is trying to update or insert using the result table which in my case is an advanced table. I am unable to figure out at what place I need to put the check. Though I am trying to handle the said condition before calling the getTransaction().commit(), I guess the DB is throwing the error even earlier which I presume is at the point of insertion into the Db which I guess happens at the EO setAttribute Level. So is it right to put the check at the setters in the EO???
    Kindly provide feedback as how to overcome this problem

    GFMIS.PK_ELTRADERID
    ON (lct.trader = exl.trader)Your ON clause should be work on the same column of your PK, that should be enough to avoid the unique constraint violation.
    Nicolas.

  • 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

  • How to create Unique constraint

    Hi,
    How can I create a unique constraint on a column in a table which has already been created.
    Thanks

    ALTER TABLE your_table ADD CONSTRAINT yrt_uk UNIQUE (some_col)
    /You may find it illuminating to read the online documentation.
    Cheers, APC

  • How to create unique constraint in ODI

    Hi
    I have view at source side, I want to store source data to target interface table.
    For that I need to create UNIQUE constraint at source side to identify the unique records.
    I have composite primary key example as follow
    desc Test_V;
    orderID NUMBER,
    itemNumber NUMBER,
    productId NUMBER,
    quantity NUMBER,
    lot_number varchar2(80)
    where
    PRIMARY KEY (orderID, itemNumber,lot_number);
    Some times, lot_number can be null, So, I can't use lot_number in composite key (as per requirement)
    Please any body can help me on it
    Thanks
    Phani

    Hi
    Hope this may help
    http://mhimu.wordpress.com/2009/05/04/odi-incremental-update-and-surrogate-key-using-database-sequence/
    but some cases it is not working
    Thanks
    Phani

  • How to catch 'too-many-rows' exception for the SELECT ... INTO statement?

    Given The following SQL statement:
    SELECT COLUMN1, COLUMN2
    INTO ITEM1, ITEM2
    FROM TABLE1
    WHERE COLUMN1 = X AND
    COLUMN2 = Y;
    As I know, NO_DATA_FOUND error will be generated when nothing is found. However, if more than 1 row is returned, what is the reserved error word should i use?
    Thanks for any help!

    Bearing in mind exception names have underscores rather than hyphens, you have answered your own question!

  • Uniqueness Constrain violation:exception"BusinessProcess.proxy.SercieError"

    HI ,
    While creating the web servise proxy by using of WSDL doc URL
    http://soa6.com:8888/integration/services/IdentityService/configuration?WSDL
    ( of PortName ' IdentityConfigServicePort') . I am getting the exception like
    uniqueness Constraint violation : exception "BusinessProcess.proxy.SercieErrorType" already found.
    Please help me how to resolve this issue.
    Thanks in advance, ....

    Hi Calvin,
    You may want to try the 'no data binding' option on the proxy generation. This may enable you to go ahead, with a proxy that is not trying to generate Java code.
    Yo can also try to make a local copy of your WSDL and remove the duplicate type declaration. Using the analyze command from WSA CLI is a quick way to do this itterative testing, as it will not generate the code. Once you have the analyze command going thourg the WSDL, you can go back to using genProxy.
    You can find the documnetation here:
    http://download.oracle.com/docs/cd/B32110_01/web.1013/b28974/wsassemble.htm#CHDBBDBF
    Hope it helps,
    -Eric

  • Add a unique constraint on binary XML table

    How add a unique constraint of "brevet" field?
    The following INSERT failed
    SQL Error: ORA-19025: EXTRACTVALUE renvoie la valeur d'un seul noeud
    19025. 00000 - "EXTRACTVALUE returns value of only one node"
    If the ALTER is made after the INSERT is done, INSERT is valid but ALTER failed with the same error message!
    /* copy the file compavions.xml
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <compagnie>
         <comp>AB</comp>
         <flotte>
              <avion immat="F-WTSS" capacite="90">
                   <typeAv>Concorde</typeAv>
              </avion>
              <avion immat="F-GFDR" capacite="145">
                   <typeAv>A320</typeAv>
              </avion>
              <avion immat="F-GTYA" capacite="150">
                   <typeAv>A320</typeAv>
              </avion>
         </flotte>
         <nomComp>Air Blagnac</nomComp>
         <pilotes>
              <pilote>
              <brevet>PL-1</brevet>
              <nom>C. Sigaudes</nom>
              </pilote>
              <pilote>
              <brevet>PL-2</brevet>
              <nom>P. Filloux</nom>
              </pilote>
         </pilotes>
    </compagnie>
    in C:\...
    --DROP DIRECTORY repxml;
    --CREATE DIRECTORY repxml AS 'C:\...';
    DROP TABLE pilote_binary_xml5;
    CREATE TABLE pilote_binary_xml5 OF XMLType
    XMLTYPE STORE AS BINARY XML
    VIRTUAL COLUMNS
    (col AS (EXTRACTVALUE(OBJECT_VALUE, '/compagnie/pilotes/pilote/brevet')));
    ALTER TABLE pilote_binary_xml5 ADD CONSTRAINT brevet_unique UNIQUE (col);
    INSERT INTO pilote_binary_xml5 VALUES (XMLType(BFILENAME ('REPXML','compavions.xml'), NLS_CHARSET_ID ('AL32UTF8')));
    --ALTER TABLE pilote_binary_xml5 ADD CONSTRAINT brevet_unique UNIQUE (col);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    You could try something like
    (extract(OBJECT_VALUE,compagnie/pilotes/pilote/brevet').getStringVal());
    but this is probably unadvisable.
    I suggest an alternative is for you to look at XMLINDEX so that you can bring the 'proper' XML functions into play like XMLTABLE etc.

  • Need help: unique constraint

    Hey please tell How to add unique constraint on two columns on a table say
    Name and id
    Name should be case independent unique
    something like
    alter table xyz. add unique constraint on (upper(name),id )
    Thnx

    SQL> create table xyz
      2  ( name varchar2(10)
      3  , id number(4)
      4  )
      5  /
    Tabel is aangemaakt.
    SQL> alter table xyz. add unique constraint on (upper(name),id )
      2  /
    alter table xyz. add unique constraint on (upper(name),id )
    FOUT in regel 1:
    .ORA-00903: invalid table name
    SQL> create unique index i1 on xyz (upper(name),id)
      2  /
    Index is aangemaakt.
    SQL> insert into xyz values ('abc',1)
      2  /
    1 rij is aangemaakt.
    SQL> insert into xyz values ('def',1)
      2  /
    1 rij is aangemaakt.
    SQL> insert into xyz values ('DEF',1)
      2  /
    insert into xyz values ('DEF',1)
    FOUT in regel 1:
    .ORA-00001: unique constraint (RWK.I1) violatedRegards,
    Rob.

  • Handling unique constraint exception

    Hi,
    I have a problem with handling constraint exception. I'm wondering is there a way to get the value that violates unique constraint. Use case is following, user creates document and then adds 50 records and manually enters inventory and serial numbers that should be unique he tries to commit but since he entered let's say inventory number that already exists in database I get exception and I can only show him error message "you've entered non unique inventory or serial numbers" so then he has to go record by record and try to figure where is the mistake. it would be much easier if I could tell him that there's a duplicate inventory and serial number in record number 34. is this possible?
    thanks in advance,
    Tomislav.

    Tomislav,
    May be a good case to use a custom DBTransactionImpl, as detailed [url http://forums.oracle.com/forums/thread.jspa?threadID=700740&tstart=0]here. Something like this, perhaps (just off the top of my head):
      public void postChanges(TransactionEvent te)
        try
          super.postChanges(te);
        catch (DMLConstraintException ex)
          Row r = ex.getEntityRow();
          AttributeDef attrs[] = r.getStructureDef().getAttributeDefs();
          int numAttrs = attrs.length;
          String msg = "Duplicate key found. Primary key values: ";
          for (int i = 0; i < numAttrs; i++)
            if (attrs.isPrimaryKey())
    msg = msg + attrs[i].getName() + ":" + r.getAttribute(i).toString() + " ";
    throw new JboException(msg);
    Note that this code would catch all DML exceptions, not just unique key violations. That would be left as an exercise for the reader ;)
    John

  • TopLink inserts when it should update, unique constraint exception

    The title says most of it. I am creating a series of objects and then updating them in rapid succession. It would be great to handle all the values during the insert, but it's not possible for this process. The majority of the time, the cached object is updated correctly and no problem occurs, but every once in a while TopLink tries to re-insert the previously inserted object, instead of updating it. Obviously this throws a unique constraint exception for the PK, and boots me out of the process.
    I can refreshObject and then it works fine. I'm looking for the underlying cause though. I want to be able to use the cache!
    Thanks!!
    Aaron
    Oracle JDBC driver Version: 10.2.0.3.0
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    TopLink Release-Designation: 10g Release 3

    Hello,
    How are you obtaining these objects to update them? The likely cause is that you are running out of memory and the objects in the shared identity map are getting garbage collected due to weak references. This means that when they get registered, TopLink can't find them in the cache so assumes they are new (the default existence check is check cache).
    If this is the case, there are a few options.
    1) Increase the size of the cache for the class in question to something more appropriate for your application, or use a fullIdentyMap so nothing ever gets pushed out. Of course, a FullIdentityMap should not be used lightly as it prevents its objects from beign gc'd and has consequences to related objects as described in:
    Caching Causing Memory Leak Effect
    Both these options will require more memory resources though, so if garbage collection is running and clearing out the references because you are already low on memory, this might make GC need to run more frequently
    2) Increase the JVM memory. This assumes completely that GC is clearing out the unused weak references from your cache because it is low on memory - GC can still occur so it doesn't guarantee the problem will be any better
    3) Read in the object through the UnitofWork before making changes (instead of using RegisterObject on existing objects), use the registerExistingObject for known existing objects or use the uow mergeClone method. Merge should cause the object to be read from the database if it is not in the cache, but it depends on the existence options used
    Best Regards,
    Chris

  • How to catch exception throw bc4j

    Dear Forum
    I am user of JDeveloper Swing application.
    while exception throw from bc4j some particular
    type error such as (oracle.jbo.DMLException) JBO-26041
    message display.
    i want to catch error no 26041 inorder to display own
    messageBox.
    There is two methods
    1-:
    i used messageBundle class i overite message string but unable to change dialogBox,i want to use own dialog.
    2-:
    And i fund ,DML exception message return from JUErrorHandlerDlg class.So using this subclass how
    to catch and throw own message.
    Plase send me some code to write sub class of JUErrorHandlerDlg.

    You want this method System to throw an exception if the String[] is empty?
    public void system( ObjectOutputStream output, String cmd []  ) {
       if (cmd.length == 0)
          throw new IllegalArgumentException("Hey! This is an empty array!");
    //...rest of your method
    }You can choose for yourself which exception type is most appropriate. You can in theory always use the base Exception but is not very specific nor recommended. In this case, I think an existing unchecked exception such as IllegalArgumentException would be the most appropriate.

  • How to catch exception in JSP????

    how to catch exception in JSP?
    I use JDeveloper 3.1
    I use connection with database .
    When I insert record in database
    when have duplicate of primary key
    how to catch this exception and
    back to previous page?
    I trying with folowing:
    <jsp:useBean id="RowEditor" class="oracle.jbo.html.databeans.EditCurrentRecord" scope="request">
    <% try {
    RowEditor.setUseJS(true);
    RowEditor.initialize(pageContext, "package2_Package2Module.Drzavi1View");
    RowEditor.setSubmitText("Save");
    RowEditor.setTargetUrl("Drzavi1View_SubmitInsertForm.jsp");
    RowEditor.createNewRow();
    RowEditor.setReleaseApplicationResources(true);
    RowEditor.render();
    catch(Exception e) {
    %>
    <script>
    alert("primary key duplication");
    history.back();
    </script>
    <% } %>
    but i't not working
    please help me

    i catch exceptions as you do, i don't have any problem...
    are you throwing the exception from your bean?
    actually i don't catch an Exception, but an SQLException...
    but it works... here is my code...
         try
    myclass.addElement(); // this is an insert into Oracle
    catch( DataBaseFailException e ) /// an exception that i throws inside after i receive an SQLException
              session.setAttribute("gMessage","e.getMessage()); // error code

Maybe you are looking for

  • Can i run Mac OS X on Mac Mini under a "bare metal" Hypervisor?

    Unfortunately, I can't leave Windows because of heavy amount of legacy software which cannot be easily transfered to Mac OS X (for example, databases running on MSSQL). On the other side I like Mac Mini hardware for its size, noise level and power co

  • Open in OS X encrypted files created under os 9 with "File Encryption"

    Hello I have a lot of files still encrypted by the tool "File Encryption" under OS 9. Now I want to open them on my MacBook Pro under OS X! Is there a tool which can do this decryption. Or is their a Programm which can do an convert to a more up to d

  • Palm Z22 frozen touch screen

    Hi -- I can turn on my Palm Z22, I can reset it, i can use the buttons, but the touch screen doesn't work at all.  Does anyone know a fix for this? Thanks, Betsy Post relates to: Palm Z22

  • RAW and JPEG Management

    I'm shooting RAW (to CF card) + JPEG (to SD card) on my Canon 5D Mk III. When I import to Lightroom 4.1 RC2 I see the JPEG and RAW (CR2) image side by side. I'm coming from Aperture 3 where the two gets stacked together and I can select which one (th

  • Sutdown of a Database in Shared Server Modus

    Hi, I have set up today a database called "db03" in Shared Server Mode. After the installation everything looked fine beside that there was no entry in the listener.ora file for the Database. Anyways I added the entry to the listener.ora and was able