oracle触发器,表发生了变化,触发器/函数不能读他,求修改
createorreplacetriggerTRI_BY_CONTRACT_ALLafterinsertonby_contract_allforeachrowdeclar...
create or replace trigger TRI_BY_CONTRACT_ALL
after insert on by_contract_all
for each row
declare
-- local variables here
numorder number;
begin
select max(CONTRACT_NUMBER_ORDRE)
into numorder
from BY_CONTRACT_ALL
where CONTRACT_NUMBER_YEAR=:new.CONTRACT_NUMBER_YEAR
and CONTRACT_NUMBER_COMPANY=:new.CONTRACT_NUMBER_COMPANY
and CONTRACT_NUMBER_TYPE=:new.CONTRACT_NUMBER_TYPE;
if numorder is null then
update BY_CONTRACT_ALL
set CONTRACT_NUMBER_ORDRE=1,
CONTRACT_NUMBER=:new.CONTRACT_NUMBER_YEAR+:new.CONTRACT_NUMBER_COMPANY+:new.CONTRACT_NUMBER_TYPE+'-01'
where CONTRACT_ID=:new.contract_id;
else
if numorder<10 then
update BY_CONTRACT_ALL
set CONTRACT_NUMBER_ORDRE=numorder+1,
CONTRACT_NUMBER=:new.CONTRACT_NUMBER_YEAR+:new.CONTRACT_NUMBER_COMPANY+:new.CONTRACT_NUMBER_TYPE+'-0'+(numorder+1)
where CONTRACT_ID=:new.contract_id;
else
update BY_CONTRACT_ALL
set CONTRACT_NUMBER_ORDRE=numorder+1,
CONTRACT_NUMBER=:new.CONTRACT_NUMBER_YEAR+:new.CONTRACT_NUMBER_COMPANY+:new.CONTRACT_NUMBER_TYPE+'-'+(numorder+1)
where CONTRACT_ID=:new.contract_id;
end if;
end if;
end TRI_BY_CONTRACT_ALL; 展开
after insert on by_contract_all
for each row
declare
-- local variables here
numorder number;
begin
select max(CONTRACT_NUMBER_ORDRE)
into numorder
from BY_CONTRACT_ALL
where CONTRACT_NUMBER_YEAR=:new.CONTRACT_NUMBER_YEAR
and CONTRACT_NUMBER_COMPANY=:new.CONTRACT_NUMBER_COMPANY
and CONTRACT_NUMBER_TYPE=:new.CONTRACT_NUMBER_TYPE;
if numorder is null then
update BY_CONTRACT_ALL
set CONTRACT_NUMBER_ORDRE=1,
CONTRACT_NUMBER=:new.CONTRACT_NUMBER_YEAR+:new.CONTRACT_NUMBER_COMPANY+:new.CONTRACT_NUMBER_TYPE+'-01'
where CONTRACT_ID=:new.contract_id;
else
if numorder<10 then
update BY_CONTRACT_ALL
set CONTRACT_NUMBER_ORDRE=numorder+1,
CONTRACT_NUMBER=:new.CONTRACT_NUMBER_YEAR+:new.CONTRACT_NUMBER_COMPANY+:new.CONTRACT_NUMBER_TYPE+'-0'+(numorder+1)
where CONTRACT_ID=:new.contract_id;
else
update BY_CONTRACT_ALL
set CONTRACT_NUMBER_ORDRE=numorder+1,
CONTRACT_NUMBER=:new.CONTRACT_NUMBER_YEAR+:new.CONTRACT_NUMBER_COMPANY+:new.CONTRACT_NUMBER_TYPE+'-'+(numorder+1)
where CONTRACT_ID=:new.contract_id;
end if;
end if;
end TRI_BY_CONTRACT_ALL; 展开
1个回答
展开全部
原因是触发器递归。
当为by_contract_all 表插入记录时触发去修改update BY_CONTRACT_ALL。
当为by_contract_all 表插入记录时触发去修改update BY_CONTRACT_ALL。
更多追问追答
追问
怎么改呢
追答
触发器应该是由于一个表的变化触发另一个表的更新。就是避免由于表本身的变化更新自身的表。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
ZESTRON
2024-09-04 广告
2024-09-04 广告
在Dr. O.K. Wack Chemie GmbH,我们高度重视ZESTRON的表界面分析技术。该技术通过深入研究材料表面与界面的性质,为提升产品质量与可靠性提供了有力支持。ZESTRON的表界面分析不仅涵盖了相变化、化学反应、吸附与解吸...
点击进入详情页
本回答由ZESTRON提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询