求解一个oracle触发器,谢谢两张表表1:person
id:number, --主键id
unitid:number, --单位id,来源于表2中的主键表2:unit
id:number, --主键id
countUser:number, --该单位共有多少人员
lastjoindate:date --最后加入该单位的日期我想在表person中插入一条记录的时候,自动更新表unit中记录,
更新1,在统计该单位有多少人,或者原来的值+1,
更新2,最后加入该单位的时间,(或者说是该单位最后使用的日期),谢谢指教,郁闷好长时间了
id:number, --主键id
unitid:number, --单位id,来源于表2中的主键表2:unit
id:number, --主键id
countUser:number, --该单位共有多少人员
lastjoindate:date --最后加入该单位的日期我想在表person中插入一条记录的时候,自动更新表unit中记录,
更新1,在统计该单位有多少人,或者原来的值+1,
更新2,最后加入该单位的时间,(或者说是该单位最后使用的日期),谢谢指教,郁闷好长时间了
after insert
on person
for each row
begin
update unit set countuser=countuser+1,
lastjoindate=sysdate where id=:new.unitid;
end tg_person;
after insert
on person
for each row
begin
update unit set countuser=countuser+1,
lastjoindate=sysdate where id=:new.unitid; IF sql%rowcount = 0 THEN
insert into unit(id, countuser, lastjoindate)
values(:new.unitid, 1, sysdate);
END IF;
end tg_person;