OK, here's what I'm doing:
I want to disable my AFTER INSERT trigger by checking if the new row is a duplicate or is new (based on the criteria in the stored procedure). The BEFORE INSERT trigger calls a stored procedure which will enable or disable the AFTER INSERT trigger. The problem: I was getting "can't use COMMIT statements" error. So, I added the "pragam autonomous transaction" to the stored procedure. Now, whenever I do an insert, the system just hangs.
Any ideas?
The stored procedure:
The before insert trigger:
I want to disable my AFTER INSERT trigger by checking if the new row is a duplicate or is new (based on the criteria in the stored procedure). The BEFORE INSERT trigger calls a stored procedure which will enable or disable the AFTER INSERT trigger. The problem: I was getting "can't use COMMIT statements" error. So, I added the "pragam autonomous transaction" to the stored procedure. Now, whenever I do an insert, the system just hangs.
Any ideas?
The stored procedure:
Code:
CREATE OR REPLACE PROCEDURE SP_ALTER_TRIGGER (
triggerName IN varchar2,
enableDisable IN varchar2
)
AS
PRAGMA AUTONOMOUS_TRANSACTION;
strSQL varchar2(100);
begin
IF enableDisable = 'ENABLE' THEN
strSQL := 'ALTER TRIGGER ' || triggerName || ' ENABLE';
EXECUTE IMMEDIATE (strSQL);
ELSE
strSQL := 'ALTER TRIGGER ' || triggerName || ' DISABLE';
EXECUTE IMMEDIATE (strSQL);
END IF;
END;
The before insert trigger:
Code:
CREATE OR REPLACE TRIGGER CLIN_DTL_B_I_R BEFORE
INSERT ON CLIN_DETAILS FOR EACH ROW DECLARE
rowCount int;
strSQL varchar2(100);
BEGIN
--the sequence
If :new.CLIN_DTL_ID Is Not Null Then
Raise_APPLICATION_ERROR(-20000, 'PK cannot be specified in query');
Else
Select S_CLIN_DTL.nextVal into :new.CLIN_DTL_ID From dual;
End If;
--check if this CLIN already exists. If so, disable the AFTER insert trigger
SELECT Count(*) into rowCount
FROM CLIN_DETAILS
WHERE CLIN_NUM = :NEW.CLIN_NUM
AND CTRT_ID = :NEW.CTRT_ID;
IF rowCount = 0 THEN
SP_ALTER_TRIGGER ('CLIN_DTL_A_I_R', 'ENABLE');
ELSE
SP_ALTER_TRIGGER ('CLIN_DTL_A_I_R', 'DISABLE');
END IF;
END;