如何在oracle中调用单独的触发函数。我了解在postgres中,调用触发函数的语法为
create OR replace trigger_test
after update or delete on person_info
FOR EACH ROW EXECUTE FUNCTION trig_function();
同样在postgres中,我可以在函数trig_function()中获得表person_info的所有旧值和新值。
有没有一种方法可以在oracle中模拟相同的东西,因为我发现了有关触发器的文档与postgres触发器的对比。
在Oracle中,触发器是由标题(CREATE OR REPLACE TRIGGER...
)和PL / SQL块组成的整体条目,在发生触发事件时将调用该块。一个例子是:
CREATE OR REPLACE TRIGGER EMPLOYEES_BIU
BEFORE INSERT OR UPDATE ON EMPLOYEES
FOR EACH ROW
DECLARE -- This is only included to demonstrate that
nSome_variable NUMBER; -- you can include a DECLARE section.
BEGIN
IF INSERTING THEN
:NEW.ADD_DATE := SYSDATE;
:NEW.ADD_USER := UID;
ELSIF UPDATING THEN
:NEW.ADD_DATE := :OLD.ADD_DATE;
:NEW.ADD_USER := :OLD.ADD_USER;
:NEW.MTC_DATE := SYSDATE;
:NEW.MTC_USER := UID;
END IF;
END EMPLOYEES_BIU;
旧值和新值可通过伪行:OLD
和:NEW
获得。
我希望您尝试从触发器内调用函数。如果是这种情况,那么您可以执行类似的操作
create or replace trigger trigger_test
after update or delete on person_info
for each row
declare
c_person person_info<specify your type>%TYPE
begin
if trig_function(:NEW.person) != c_person; -- not sure what your function returns
--your logic here
end if;
end;
/
或者您可以做类似的事情>>
create or replace trigger trigger_test
after update or delete on person_info
for each row
begin
if trig_function(:NEW.person) != "ABC" ---- not sure what your function returns
----implement your logic with the function
end if;
end;
/