Database trigger to insert duplicated rows on audit table
554553Sep 13 2011 — edited Sep 15 2011Hi
It is possible to insert duplicate rows (at the moment database generate PK violation constraint for one specific table) within an audit table ?
Certain code like this is not working, always the whole transaction makes a rollback and audit table will be empty:
CREATE OR REPLACE TRIGGER USER.audit_TABLE_TRG
before INSERT ON USER.TABLE
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
BEGIN
declare
V_conteo number(1) := 0;
duplicate_record EXCEPTION;
begin
select count(*)
into V_conteo
from USER.TABLE
where <PK conditions>
;
if V_conteo > 0 then
begin
INSERT INTO USER.AUDIT_TABLE
(<>)
VALUES
(<>);
raise duplicate_record;
exception
when duplicate_record then
INSERT INTO USER.AUDIT_TABLE
(<>)
VALUES
(<>);
raise_application_error(-20019,'Duplicated column1/column2:'||:NEW.column1||'/'||:NEW.column2);
when others then
dbms_output.put_line('Error ...'||sqlerrm);
end;
end if;
end;
END;
/