插入前后的Oracle触发器
Oracle trigger before and after insert
是否可以在 Oracle 中只创建一个在数据插入 table 之前和之后触发的触发器?
begin
if inserting THEN
-- This code should be run before insertion:
:new.cr_timestamp := SYSTIMESTAMP;
IF :NEW.id IS NULL THEN
SELECT sq_table_id.NEXTVAL
INTO :NEW.id
FROM dual;
END IF;
-- Now I want code which run after the insertion..
end if;
end;
那么是否有一个标志表明它是在插入之前还是之后?
可以这样写。
CREATE OR REPLACE TRIGGER compound_trigger_name
FOR [INSERT|DELETE|UPDATE [OF column] ON table
COMPOUND TRIGGER
--Executed before DML statement
BEFORE STATEMENT IS
BEGIN
NULL;
END BEFORE STATEMENT;
--Executed aftereach row change- :NEW, :OLD are available
AFTER EACH ROW IS
BEGIN
NULL;
END AFTER EACH ROW;
--Executed after DML statement
AFTER STATEMENT IS
BEGIN
NULL;
END AFTER STATEMENT;
END compound_trigger_name;
是否可以在 Oracle 中只创建一个在数据插入 table 之前和之后触发的触发器?
begin
if inserting THEN
-- This code should be run before insertion:
:new.cr_timestamp := SYSTIMESTAMP;
IF :NEW.id IS NULL THEN
SELECT sq_table_id.NEXTVAL
INTO :NEW.id
FROM dual;
END IF;
-- Now I want code which run after the insertion..
end if;
end;
那么是否有一个标志表明它是在插入之前还是之后?
可以这样写。
CREATE OR REPLACE TRIGGER compound_trigger_name
FOR [INSERT|DELETE|UPDATE [OF column] ON table
COMPOUND TRIGGER
--Executed before DML statement
BEFORE STATEMENT IS
BEGIN
NULL;
END BEFORE STATEMENT;
--Executed aftereach row change- :NEW, :OLD are available
AFTER EACH ROW IS
BEGIN
NULL;
END AFTER EACH ROW;
--Executed after DML statement
AFTER STATEMENT IS
BEGIN
NULL;
END AFTER STATEMENT;
END compound_trigger_name;