Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to Catch Unique Constraint in Exception

cpAug 14 2012 — edited Aug 14 2012
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?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 11 2012
Added on Aug 14 2012
12 comments
15,699 views