CREATE OR REPLACE TRIGGER TEST_COMPOUND
FOR INSERT OR UPDATE ON TEST_TRG
COMPOUND TRIGGER
v_num number;
v_time timestamp;
v_date date;
procedure set_defaults is
begin
if INSERTING then
if :new.a1 is null then
:new.a1 := v_num;
end if;
if :new.a3 is null then
:new.a3 := v_time;
end if;
if :new.a4 is null then
:new.a4 := v_date;
end if;
end if;
end;
--Executed before DML statement BEFORE STATEMENT IS
BEFORE STATEMENT IS
BEGIN
v_time := systimestamp;
v_date := sysdate;
END BEFORE STATEMENT;
--Executed before each row change- :NEW, :OLD are available
BEFORE EACH ROW IS
BEGIN
if inserting then
select nvl(max(a1), 0) + 1 into v_num from TEST_TRG;
end if;
if updating then
v_num := :old.a1;
end if;
set_defaults;
END BEFORE EACH ROW;
END;