有两个表,分别发test1和test2在插入test1表里会去看看test2表中有没有对应test1的记录要是没有就插入,要是有就统计一下test2中的一字段加上test1中的一个字段加起来修改一下。
我的写法为:
create or replace trigger test_trigger
before insert on test1
for each row
DECLARE numb number;
ammount number;
begin
select count(*) into numb from test2 where sys_id=:new.sys_id and person_id=:new.person_id
if numb<1 then
insert into test2(day_integral_id,sys_id,person_id,integral_ammount,integral_date,last_modify_time) values(sq_wap_day_integral.nextval,:new.sys_id,:new.person_id,:new.integral_ammount,sysdate,sysdate);
elsif numb==1 then
select integral_ammount into ammount from test2 where sys_id=:new.sys_id and person_id=:new.person_id;
update test2 set integral_ammount=:new.integral_ammount+ammount,last_modify_time=sysdate where sys_id=:new.sys_id and person_id=:new.person_id;
end if;
end;
我的写法为:
create or replace trigger test_trigger
before insert on test1
for each row
DECLARE numb number;
ammount number;
begin
select count(*) into numb from test2 where sys_id=:new.sys_id and person_id=:new.person_id
if numb<1 then
insert into test2(day_integral_id,sys_id,person_id,integral_ammount,integral_date,last_modify_time) values(sq_wap_day_integral.nextval,:new.sys_id,:new.person_id,:new.integral_ammount,sysdate,sysdate);
elsif numb==1 then
select integral_ammount into ammount from test2 where sys_id=:new.sys_id and person_id=:new.person_id;
update test2 set integral_ammount=:new.integral_ammount+ammount,last_modify_time=sysdate where sys_id=:new.sys_id and person_id=:new.person_id;
end if;
end;
解决方案 »
- oracle的 where 1=1 后面能跟一个 %1$s 吗?是什么意思?
- 我的Oracle见鬼啦
- 我的PL/SQL第一次执行语句都会出现“动态执行表不可访问,本会话的自动统计被禁止。在执行菜单里你可以禁止统计,或在v$session,v$sesstat和v$statname表获得选择权限”
- 大家能否帮忙列一下锁表的几种典型原因
- oracle 批量导出数据到 excel文件吗?
- 请问oracle中如何select到文件,及运行外部exe命令
- 请问如何把文本格式的数据导入到Oracle中?
- 关于访问控制
- 创建数据库ORA-12203: TNS:unable to connect to destination
- 建立用户的问题?
- java程序从Oracle中查出4万多条数据,然后全部写入Excel文件,怎么写并且效率高呢?
- 招聘
numb==1多了一个=