Oracle Database - Trigger

> Database > Oracle Database

1 - Example

Trigger used in apex

CREATE OR REPLACE TRIGGER myTableTrigger
BEFORE INSERT OR UPDATE ON myTable
FOR each ROW
BEGIN
    IF inserting THEN
        IF :NEW.myPk IS NULL THEN
          SELECT mySequence.nextval INTO :NEW.myPk FROM dual;
        END IF;
        :NEW.created_on := systimestamp;
        :NEW.created_by := nvl(v('APP_USER'),nvl(sys_context('userenv','os_user'),USER));
		:NEW.
    elsif updating THEN
         :NEW.updated_on := systimestamp;
         :NEW.updated_by := nvl(v('APP_USER'),nvl(sys_context('userenv','os_user'),USER));
    END IF;
END;
/

2 - Documentation / Reference