Triggers

Other topics

Before INSERT or UPDATE trigger

CREATE OR REPLACE TRIGGER CORE_MANUAL_BIUR
  BEFORE INSERT OR UPDATE ON CORE_MANUAL
  FOR EACH ROW
BEGIN
  if inserting then
    -- only set the current date if it is not specified        
    if :new.created is null then
      :new.created := sysdate;
    end if;
  end if;

  -- always set the modified date to now
  if inserting or updating then
    :new.modified := sysdate;
  end if;
end;
/

Syntax:

  • CREATE [ OR REPLACE ] TRIGGER trigger_name
  • BEFORE UPDATE [or INSERT] [or DELETE]
  • ON table_name
  • [ FOR EACH ROW ]
  • DECLARE
  • -- variable declarations
  • BEGIN
  • -- trigger code
  • EXCEPTION
  • WHEN ...
  • -- exception handling
  • END;

Contributors

Topic Id: 7674

Example Ids: 25214

This site is not affiliated with any of the contributors.