回 帖 发 新 帖 刷新版面

主题:触发器??


求救!纠正触发器!

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

采购表
    create table SYSTEM.purchase(
        product_ID number(10) primary key,
       purchase_quantity number(5) not null);
当产品数量小于10时,触发器实现自动生成采购记录!
create or replace trigger add_pur
after update on system.product for each row
 declare
 n number;
 begin
 select quantity into n
 from system.product where product_id=:new.product_id;
 dbms_output.put_line(n);
 if n<10 then
 insert into system.purchase values(:new.product_id,300);
 end if;
 end add_pur;

回复列表 (共1个回复)

沙发

应该这么写
create or replace trigger add_pur
after update on system.product for each row
declare
begin
if :new.quantity<10 then
insert into system.purchase values(:new.product_id,300);
end if;
end add_pur;
你那样写,数据时无法读入到n里面,你直接可以把新的quantity值拿来使用

我来回复

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