Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ajin/20589271e9858538eef6560722556c48 to your computer and use it in GitHub Desktop.
Save ajin/20589271e9858538eef6560722556c48 to your computer and use it in GitHub Desktop.
Default Oracle trigger for insert and update statement
create or replace TRIGGER "BIU_<TABLE_NAME>"
before insert or update on "<TABLE_NAME>"
for each row
begin
if inserting and :new.id is null then
select "<TABLE_NAME>_ID_SEQ".nextval into :NEW."ID" from sys.dual;
end if;
if inserting then
:new.created_by := nvl(apex_application.g_user,USER);
:new.created_date := localtimestamp;
:new.last_modified_by := nvl(apex_application.g_user,USER);
:new.last_modified_date := localtimestamp;
end if;
if updating then
:new.last_modified_by := nvl(apex_application.g_user,USER);
:new.last_modified_date := localtimestamp;
end if;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment