Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Easy Audit Trails
create or replace trigger master_table_audit
after insert or update or delete on master_table
for each row
--
begin
if UPDATING then
insert into audit_table (
pk_uid
,edit_user
,edit_datetime
,trg_action
--additional audit columns
) values (
:new.pk_uid
,:new.edit_user
,sysdate
,'UPDATE'
--additional audit columns
);
elsif DELETING then
insert into audit_table (
edit_user
,edit_datetime
,pk_uid
,trg_action
--additional audit columns
) values (
:old.edit_user
,sysdate
,:old.pk_uid
,'DELETE'
--additional audit columns
);
else
insert into audit_table (
pk_uid
,edit_user
,edit_datetime
,trg_action
) values (
:new.pk_uid
,:new.edit_user
,sysdate
,'INSERT'
--additional audit columns
);
end if;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment