我有一个表触发器如下:
CREATE OR REPLACE TRIGGER PAT_BUR_DOB_TRG
BEFORE UPDATE OF DOB
ON PAT
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
-- PL/SQL Block
begin
tgln_sys_error_pkg.compare_dates(trunc(add_months(:new.dob, -12)),
trunc(tgln_sys_error_pkg.GET_LIST_DATE(:old.pat_id)),
tgln_sys_errnums_pkg.en_retr_waitlist_date);
end;
--------------------------------------
我有一个由上面的触发器调用的包,包的代码如下:
CREATE OR REPLACE PACKAGE TGLN_SYS_ERROR_PKG AS
/* To compare two dates against each other. */
PROCEDURE COMPARE_DATES
(P_DATE_LOW date
,P_DATE_HIGH date
,P_ERROR_CODE number
);
FUNCTION GET_LIST_DATE
(P_PAT_ID number)
RETURN DATE;
END TGLN_SYS_ERROR_PKG;
--------------------------------------
包体如下所示:
CREATE OR REPLACE PACKAGE BODY TGLN_SYS_ERROR_PKG AS
FUNCTION GET_LIST_DATE(P_PAT_ID number) RETURN DATE IS
v_ret_date date;
begin
--select to_date('01-JAN-1980') into p_Date from dual;
select max(pwl.eff_date)
into v_ret_date
from pat, pat_register pr, pat_register_org_det prod, pat_wait_list pwl
where pat.pat_id = pr.pat_id
and pr.patr_id = prod.patr_id
and prod.prod_id = pwl.prod_id
and pat.pat_id = P_PAT_ID
and rownum < 2
AND pwl.exp_date is null;
return nvl(v_ret_date, to_date(null));
exception
when no_data_found then
return to_date(null);
end GET_LIST_DATE;
PROCEDURE COMPARE_DATES
(P_DATE_LOW date
,P_DATE_HIGH date
,P_ERROR_CODE number
)
IS
begin
if nvl(p_date_low,sysdate-10000)>nvl(p_date_high,sysdate+10000) then
raise_application_error(p_error_code,null);
end if;
end compare_dates;
end TGLN_SYS_ERROR_PKG;
--------------------------------------
CREATE OR REPLACE PACKAGE TGLN_SYS_ERRNUMS_PKG IS
en_retr_waitlist_date CONSTANT INTEGER := -20088; --Patient waitlist effective dates must not be less than or equal to patient's date of birth minus one year ( DOB - 1 year).
END TGLN_SYS_ERRNUMS_PKG;
--------------------------------------
每当Oracle Forms更新DOB数据时,我都会收到如下错误:
Oracle Form FRM-40735:ON-ERROR触发器引发了未处理的异常ORA-06502
但是,当我硬编码如下:
select to_date('01-JAN-1980') into p_Date from dual;
代替下面这段代码,表单工作正常。
select max(pwl.eff_date)
into v_ret_date
from pat, pat_register pr, pat_register_org_det prod, pat_wait_list pwl
where pat.pat_id = pr.pat_id
and pr.patr_id = prod.patr_id
and prod.prod_id = pwl.prod_id
and pat.pat_id = P_PAT_ID
and rownum < 2
AND pwl.exp_date is null;
我确实将p_pat_id
替换为实际值,它会弹出一个触发错误
ORA-04091: table TGLN.PAT is mutating, trigger/function may not see it
ORA-06512: at "TGLN.TGLN_SYS_ERROR_PKG",
line 130 ORA-06512: at "TGLN.PAT_BUR_DOB_TRG",
line 26 ORA-04088: error during execution of trigger 'TGLN.PAT_BUR_DOB_TRG'
View program sources of error stack?"
那么,如何解决这个问题呢?我不能硬编码日期值
答案 0 :(得分:1)
错误:强>
ORA-04091:表名发生变异,触发/功能可能看不到/
您的错误
trigger error:"ORA-04091: table TGLN.PAT is mutating
<强>原因:强>
语句执行触发器或自定义PL / SQL函数。该触发器/函数试图修改或查询当前正被触发触发器/函数的语句修改的表。
你的原因
--you're not supposed to query a table that is currently modified
--In you're case its `PAT` table being updated and querying at same time
select max(pwl.eff_date)
into v_ret_date
from pat, --here you are querying your PAT table,while updating the same table
pat_register pr, pat_register_org_det prod, pat_wait_list pwl
where pat.pat_id = pr.pat_id
and pr.patr_id = prod.patr_id
and prod.prod_id = pwl.prod_id
and pat.pat_id = P_PAT_ID
and rownum < 2
AND pwl.exp_date is null;
<强>动作:强>
解决此Oracle错误的选项包括:
重新编写触发器/函数,以便它不会尝试modify/query
相关的表PAT
。
<强>参考强>