回 帖 发 新 帖 刷新版面

主题:[讨论]求救!!触发器修改表数据!

哪位高手帮帮忙!
以下是两张表和一个触发器
修改订单表的state值时,触发器被触发,
比如:订单表里的order_quantity为1时,商品表里的quantity应该减1,可实际运行时减2!
为什么商品表的quantity值会减两遍啊?

商品表
create table system.product
(product_id number(10) primary key,
product_name char(30) not null,
quantity number(5),
price char(5));

订单表
create table system.orders
(ID number(10) primary key,
product_id number(10) not null,
order_quantity number(5),
state char(15) CHECK(state IN ('untreated','treated')));
我的触发器
create or replace trigger out_pro
before update on system.orders for each row
declare
n number;
begin
select order_quantity into n
from system.orders where id=:old.id;
update system.product set quantity=quantity-n   //这句好象执行两遍!!!
where product_id=:old.product_id;
end out_pro;

回复列表 (共1个回复)

沙发


你写的意思不明白,我试了一下,触发器本身写的就有问题

我来回复

您尚未登录,请登录后再回复。点此登录或注册