I have been working on a simple upsert trigger that is using unique index related to one column called vibki.
Table DLL info for easy access :
CREATE TABLE "D2C_EVENT_GENERATION_BOM"
( "VIBKI" VARCHAR2(40 BYTE),
"STATUS" VARCHAR2(100 BYTE),
"LASTRUNTIME" DATE
);
CREATE UNIQUE INDEX "D2C_EVENT_GENERATION_BOM_IND" ON ."D2C_EVENT_GENERATION_BOM" ("VIBKI");
--------------------------------------------------------
-- Constraints for Table D2C_EVENT_GENERATION_BOM
--------------------------------------------------------
ALTER TABLE "D2C_EVENT_GENERATION_BOM" MODIFY ("VIBKI" NOT NULL ENABLE);
Here is my trigger PL/SQL :
create or replace TRIGGER "BL_D2C_EVENT_GENERATION_BOM"
BEFORE INSERT
ON D2C_EVENT_GENERATION_BOM REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
BEGIN
UPDATE D2C_EVENT_GENERATION_BOM SET vibki = :NEW.vibki, status = 'NEW', lastruntime = sysdate
WHERE vibki = :NEW.vibki;
IF ( sql%notfound ) THEN
INSERT INTO D2C_EVENT_GENERATION_BOM (vibki,status,lastruntime)
VALUES (:NEW.vibki,'NEW',sysdate);
END IF;
END;
As it seems and quite simple, i am only firstly trying to update, if something has not found then please insert.
But this trigger doesn't work with this insert statement :
INSERT INTO D2C_EVENT_GENERATION_BOM (vibki) VALUES ('TAS2002/01');
Exception :
Error starting at line : 1 in command -
INSERT INTO D2C_EVENT_GENERATION_BOM (vibki) VALUES ('TAS2002/01')
Error report -
ORA-00036: maximum number of recursive SQL levels (50) exceeded
ORA-00036: maximum number of recursive SQL levels (50) exceeded
Can please someone support how i can achieve this error, i was using same trigger on another table, only difference was i was making a select operation to gather some values before upsert operation, so i am expecting this code to easily work but it is not working.
Any helps would be appreciated, many thanks!