【发布时间】:2017-04-05 14:32:46
【问题描述】:
请我需要有关此功能的更多帮助,该功能假定返回将由触发器检索的退休日期,并使用 DOFA“hire_date”中的值更新 EMPLOYEES_MASTER_DETAILS 表上的 EDOR“退休日期”列
函数和触发器编译成功。但是每当我更新记录时,我都会收到此错误消息...!
发生 1 个错误 ORA-04091: 表 DBA_AUWAL.EMPLOYEES_MASTER_DETAILS 正在变异,触发器/函数可能 看不到它 ORA-06512:在“DBA_AUWAL.EDOR_FUNCTION”,第 9 行
ORA-06512:在“DBA_AUWAL.EDOR_FUNCTION”,第 17 行 ORA-06512:在 “DBA_AUWAL.EDOR_IN_TRG”,第 2 行 ORA-04088:执行期间出错 触发'DBA_AUWAL.EDOR_IN_TRG'
我的功能是
create or replace function EDOR_FUNCTION(DOFA in date)
return date
is
dofa_date date;
dob_date date;
new_edor_date date;
cursor c1 is
SELECT DOFA
FROM EMPLOYEES_MASTER_DETAILS;
cursor c2 is
SELECT date_of_birth
FROM EMPLOYEES_MASTER_DETAILS;
BEGIN
open c1;
fetch c1 into dofa_date;
close c1;
open c2;
fetch c2 into dob_date;
close c2;
if dofa_date - dob_date <= 25 then new_edor_date := add_months(dofa_date, 35*12);
else new_edor_date := add_months(dob_date, 60*12);
end if;
return new_edor_date;
END;
这是触发器
create or replace TRIGGER EDOR_IN_TRG
before INSERT OR UPDATE ON EMPLOYEES_MASTER_DETAILS
FOR EACH ROW
BEGIN
:new.EDOR := EDOR_FUNCTION(:new.DOFA);
END;
【问题讨论】:
-
尝试将您的触发器设为
after而不是before,或者将此逻辑移动到存储过程中。 - Reference this question w/ your error