Question

create or replace 
TRIGGER "SUP" AFTER INSERT ON "EMP_REPORT" REFERENCING OLD AS "OLD" NEW AS "NEW" FOR EACH ROW
DECLARE

  miclaim_supervisor_count number;
  employee_company_code VARCHAR2(10);
  employee_businessunit number;
  projMgrs NUMBER;
  supId NUMBER;

  cursor  projMgrsCursor is select b.BU_MEMBER_ID
  from BU_MEMBER b, EMP_SUB_DIV s
  where s.EMP_NO = :NEW.EMP_NO
  and s.SUB_DIVISION_CODE = '01' and s.DIV_CODE = '2'
  and b.BU_ID IN (select BU_ID from BU_MEMBER where BU_MEMBER_ID = :NEW.EMP_NO);


BEGIN
        delete from MICL_SUPERVISORS where EMP_NO = :NEW.EMP_NO and IS_OVVERRIDDEN = 0;
        select count(*) into miclaim_supervisor_count from MICL_SUPERVISORS where EMP_NO = :NEW.EMP_NO and IS_OVVERRIDDEN = 1;
        select COMPANY_CODE into employee_company_code from  EMPLOYEE_MASTER where EMP_NO = :NEW.EMP_NO;


    projMgrs := 0;

if (employee_company_code ='F')then 

  OPEN  projMgrsCursor;
    LOOP

     select micl_sup_id_seq.nextval into  supId from dual;
    FETCH projMgrsCursor INTO projMgrs;
    EXIT WHEN projMgrsCursor%NOTFOUND;

    insert into SUP VALUES ((supId), (SELECT SYSDATE FROM DUAL), :NEW.ENTRYADDEDBY_EMP_NO, 3000, 0,projMgrs, NULL,:NEW.EMP_NO);
    END LOOP;   

  CLOSE projMgrsCursor;
else
    if(miclaim_supervisor_count IS NULL or miclaim_supervisor_count<1) then
    insert into SUP VALUES ((:NEW.ID), (SELECT SYSDATE FROM DUAL), :NEW.ENTRYADDEDBY_EMP_NO, 3000, 0, :NEW.SUP_EMP_NO, NULL,:NEW.EMP_NO);
    end if;
end if;

END;

I created this trigger a week go but no compilation errors But when I enter a record to EMP_REPORT it pop up an error msg saying

 *INSERT INTO"EMP_REPORT" (ID, ADDEDDATE, ENTRYADDEDBY_EMP_NO, SUP_EMP_NO, EMP_NO) VALUES ('71', TO_TIMESTAMP('19-MAR-13 09.55.57.983000000 AM', 'DD-MON-RR HH.MI.SS.FF AM'), '81', '841', '5295')
ORA-00001: unique constraint (SYS_C0023329) violated
ORA-06512: at line 1

One error saving changes to table  "EMP_REPORT":
Row 51: ORA-00001: unique constraint (SYS_C0023329) violated
ORA-06512: at line 1* 

I cant figure out where I went wrong. pls help me :(

pls note that I cant remove constraint and its a primary key

Was it helpful?

Solution

Are you sure that the error occurs in the trigger? It looks to me like the INSERT which might be failing is the one into EMP_REPORT - possibly because there's already a row in EMP_REPORT with ID = '71'. It would be helpful if you could confirm what table SYS_C0023329 is on.

However, assuming that the message is being generated by the trigger - I only see two INSERTs in your trigger, both inserting into the SUP table, so the problem must be coming from one of these INSERTs. Either

  1. There's already a row in SUP which has a key value (you don't show the names of the columns in your INSERT statements against SUP so I don't know what the field's name might be) greater than the current value of MICL_SUP_ID_SEQ.NEXTVAL, or

  2. There's a row in SUP with a key value equal to the new EMP_REPORT.ID field you've supplied in the second INSERT.

This second issue, supplying a key value from one table (EMP_REPORT) as the key value for a second table (SUP) seems a bit suspicious to me, and I'd suggest looking there first. I'd think you'd want to get a value from MICL_SUP_ID_SEQ to use in the SUP table.

To verify that the issue is caused by an insert into SUP, you might try executing the following:

SELECT *
  FROM ALL_CONSTRAINTS c
  WHERE c.CONSTRAINT_NAME = 'SYS_C0023329';

This will tell you what table the constraint is on.

Share and enjoy.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top