Skip to Main Content

Oracle Database Discussions

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!

Database trigger to insert duplicated rows on audit table

554553Sep 13 2011 — edited Sep 15 2011
Hi

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;
/
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 13 2011
Added on Sep 13 2011
7 comments
1,268 views