Skip to content

Instantly share code, notes, and snippets.

@phantom42
Created January 2, 2013 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phantom42/4437655 to your computer and use it in GitHub Desktop.
Save phantom42/4437655 to your computer and use it in GitHub Desktop.
template code to deal with the following discovered behavior -table rows were being updated without explicitly setting the updatedby value -:NEW reads the existing value of background_inv.updatedby and uses that to insert into the history table -this would create history logs associated with the incorrect user
CREATE OR REPLACE TRIGGER TIUD_BACKGROUND_INV
AFTER DELETE OR INSERT OR UPDATE
ON BACKGROUND_INV REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
v_new_updated_by := background_inv.updatedby%type ;
BEGIN
IF updating THEN
IF ( UPDATING('UPDATEDBY') )
THEN
v_new_updated_by := :NEW.updatedby;
ELSE
v_new_updated_by := null;
END IF;
-- log history table with v_new_updated_by
END IF ;
END ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment