create table cg
(C1 NUMBER primary key, C2 VARCHAR2(20), C3 NUMBER )---采购表
create table ck(
nameid NUMBER primary key,pname VARCHAR2(20) ,NUM NUMBER,IP VARCHAR2(20) )--仓库表
在采购表(cg)插入数据时仓库表(ck)记录插入的数据,数量,IP,插入的商品名字。用触发器实现
create or replace trigger m
before insert on cg
for each row
declare
k number;
pname varchar2(20);
num number;
ip varchar2(20);
begin
select count(*) into k from ck where pname=:new.c2;
if k>0 then
update ck set num=num+:new.c3 where pname=:new.c2;
else
select sys_context('userenv','ip_address') p into ip from dual;
insert into ck values (:new.c1,:new.c2,:new.c3,ip);
end if;
end;