概述
偶写的一个trigger就是不能按我的意思更新,请大侠们帮忙看看是哪的问题?谢谢!
更新结果如下
pn qty receive_quantity status
a 500 500 close
a 500 500 close
a 500 500 close
我要的结果是
pn qty receive_quantity status
a 500 500 close
a 500 500 close
a 500 200 open
当输入rcv_t.quantity 1200时把它拆分到app表更新receive_quantity。
CREATE OR REPLACE TRIGGER rcv_insertion
BEFORE INSERT
ON DEVS.RCV_T FOR EACH ROW
DECLARE
p_app_part_number VARCHAR2 (200);
p_app_qty NUMBER;
p_app_receive_quantity NUMBER;
p_count_pn NUMBER;
p_rcv_part_number VARCHAR2 (200) := :NEW.part_number;
p_rcv_quantity VARCHAR2 (200) := :NEW.quantity;
rcv_q number;
v_value number;
CURSOR cur_app
IS
SELECT part_number, qty, receive_quantity
FROM devs.app
WHERE part_number = p_rcv_part_number AND status = 'open'
order by creation_date
FOR UPDATE;
BEGIN
SELECT COUNT (*)
INTO p_count_pn
FROM devs.app
WHERE part_number = p_rcv_part_number AND status = 'open';
if p_count_pn = 0 then
insert into devs.rcv_t(transaction_id, part_number, item_description, quantity, creation_date)
values(:new.transaction_id, :new.part_number, :new.item_description, :new.quantity, :new.creation_date);
insert into devs.rcv_excess(transaction_id, part_number, item_description, excess_quantity, creation_date)
values(:new.transaction_id, :new.part_number, :new.item_description, :new.quantity, :new.creation_date);
else if p_count_pn > 0 then
OPEN cur_kanban_app;
loop
FETCH cur_app
INTO p_app_part_number, p_app_qty,
p_app_receive_quantity;
EXIT WHEN cur_app%NOTFOUND;
v_value := p_rcv_quantity;
loop
v_value := v_value - p_app_qty;
exit when v_value < p_app_qty;
if v_value > p_app_qty then
rcv_q := p_app_qty;
else if v_value < p_app_qty then
rcv_q := v_value;
end if;
end if;
end loop;
update devs.app
set receive_quantity = rcv_q, status = close
where current of cur_kanban_app;
end loop;
close cur_kanban_app;
end if;
end if;
end;
最后
以上就是欢喜发箍为你收集整理的oracle如何使用if,触发器中如何使用IF条件的全部内容,希望文章能够帮你解决oracle如何使用if,触发器中如何使用IF条件所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复