删除数据后,再对表进行操作,出现了死锁。。

createorreplacetriggerchange_totalafterinsertordeleteonstockforeachrowdeclarev_counte... create or replace trigger change_total
after insert or delete on stock
for each row
declare
v_counter int;
v_numbers number(8);
v_disrupt number(3);
v_name total.name%type;
cursor name_cur
IS
select goods_name from stock
where basket_id=:old.basket_id;
PRAGMA AUTONOMOUS_TRANSACTION;
begin
case
when inserting then
select count(*) into v_counter from stock
where goods_name=:new.goods_name;
if v_counter <>0 then
select sum(numbers) into v_numbers from stock
where goods_name=:new.goods_name;
v_numbers:= v_numbers + :new.numbers;
update total set sum_total=v_numbers
where name=:new.goods_name;
select disrupt into v_disrupt from total
where name=:new.goods_name;
update total set disrupt=v_disrupt+1
where name=:new.goods_name;
if v_numbers>=15 and v_numbers<=50 then
update total set warn='正常'
where name=:new.goods_name;
end if;
if v_numbers<15 then
update total set warn='库存不足'
where name=:new.goods_name;
end if;
if v_numbers>50 then
update total set warn='库存过剩'
where name=:new.goods_name;
end if;
else
if :new.numbers>=15 and :new.numbers<=50 then
insert into total values(:new.goods_name,:new.numbers,'正常',1);
end if;
if :new.numbers<15 then
insert into total values(:new.goods_name,:new.numbers,'库存不足',1);
end if;
if :new.numbers>50 then
insert into total values(:new.goods_name,:new.numbers,'库存过剩',1);
end if;
end if;

when deleting then
delete from stock where basket_id=:old.basket_id;
open name_cur;
loop
fetch name_cur into v_name;
exit when name_cur%notfound;
select sum(numbers) into v_numbers from stock
where goods_name=v_name;

if v_numbers=0 then
delete from total where name=v_name;
else
update total set sum_total=v_numbers
where name=v_name;
select disrupt into v_disrupt from total
where name=v_name;
update total set disrupt=v_disrupt-1
where name=v_name;
if v_numbers>=15 and v_numbers<=50 then
update total set warn='正常'
where name=v_name;
end if;
if v_numbers<15 then
update total set warn='库存不足'
where name=v_name;
end if;
if v_numbers>50 then
update total set warn='库存过剩'
where name=v_name;
end if;
end if;
end loop;
close name_cur;
end case;
commit;
end change_total;
就在 when deleting then
delete from stock where basket_id=:old.basket_id;
这里资源被咬住了好像。。在这报死锁了。。
展开
 我来答
hit_lubin
2011-04-19 · TA获得超过7889个赞
知道大有可为答主
回答量:1554
采纳率:100%
帮助的人:2022万
展开全部
呵呵,锁的问题确实是让人头疼,我也是经常遇到,因为平时总涉及比较复杂的业务,所以经常对某一个表不停的操作,经常出现这倒霉的死锁。
试试把DELETE删除操作放后边,中间处理的时候,滤掉这个要删除的数据吧
呵呵,先无耻的回答一个。
来自:求助得到的回答
壹寰(深圳)科技文化有限公司
2021-03-27 广告
不同公司提供的方案也不一样。以上内容如果还觉得不够全面,也可以沟通下壹寰(深圳)科技文化有限公司。91数据恢复是壹寰(深圳)科技文化有限公司旗下专业数据恢复品牌,91数据恢复专注于勒索病毒数据恢复、勒索病毒数据修复、数据库修复、数据库解密恢... 点击进入详情页
本回答由壹寰(深圳)科技文化有限公司提供
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式