oracle创建两个表,一个入库单录入的表A,一个是库存表B,A表有字段a、b、c,B表也有字段d、e、f,当A中插入数据时,通过判断B表中是否存在(a==d&&c==f)的记录,存在则B表更新此条记录的e字段为(b+e);如不存在B表也插入数据希望通过触发器来实现此功能
解决方案 »
- 求高人优化SQL
- 关于SQL语句中关键字
- 游标参数中包含逗号的问题
- 在java中用exp和imp导出导入,怎么知道已经导出或导入完成
- 请教在linux上oracle9i双机热备方案?
- 【求助】'OraOLEDB.Oracle.1' provider is not registered on the local machine是为什么
- 将 *.pdf 文件以数据流的方式放到数据库里面,读出来以后却报错说“文档已损坏,无法修复”。
- oracle lang raw 出错
- 对ORACLE和SqlServer都有认识的朋友请帮忙!
- oracle如何只备份一个表的近一段时间的数据(例如表中的数据总是最近一个月的)
- 一个简单的存储过程,希望高手帮我解答!!!
- 谁有ORACLE.JAR 90多兆,的相关API啊?
after insert on A
for each row
declare
v_count number;
begin
select count(1) into v_count from B where b.d=:new.a and b.f=:new.c;
if v_count=0 then --不存在,则插入对应的a,b,c到def
insert into B(d,e,f) values (:new.a,new:b,:new.c);
else
update B set e=e+:new.b where b.d=:new.a and b.f=:new.c;
end if;
end;
/
create or replace trigger tgname
after insert on A
for each row
declare
v_count number;
begin
select count(1) into v_count from B where b.d=:new.a and b.f=:new.c;
if v_count=0 then --不存在,则插入对应的a,b,c到def
insert into B(d,e,f) values (:new.a,new:b,:new.c);
else
update B set e=nvl(e,0)+nvl(:new.b,0) where b.d=:new.a and b.f=:new.c;
end if;
end;
/