+ -
当前位置:首页 → 问答吧 → oracle 触发器的问题!

oracle 触发器的问题!

时间:2011-09-06

来源:互联网

RT。。
我需要一个触发器。。两个表。。
当A表有增删改操作的时候,B表会根据A表中的一个字段来更新B表中对应类型的更新时间。。
这个要怎么写啊?
大题样子应该是这样
case ?????(这个条件怎么得到?)
where then  

作者: a392091921   发布时间: 2011-09-06

SQL code

参考下-也是刚刚学oracle
create or replace trigger TRIGGER_PSANDCARSTATUS
after insert
on scm_psorder_isdn
for each row
declare
INPSCODE VARCHAR2(100);--出库单号
spcode varchar2(200);--配送单号
outstorecode varchar2(200);--配送单上所有的出库单号
carplante varchar2(2000);--配送单上所有的车牌号
count_all_out integer;--配送单上的出库单数量
count_in_isdn integer;--已经'回执'的出库单数量

begin
   INPSCODE := :NEW.PSCODE;--把扫描编号赋值给变量
   select pscode into spcode from scm_psorder  where instr(outcode,INPSCODE,1)>0;--配送单号
   select carid into carplante from scm_psorder where pscode=spcode;--配送单上的所有车辆
   select outcode into outstorecode from scm_psorder where pscode=spcode;--配送单上的所有出库单号

   update scm_outstore set outtype=2 where outcode=INPSCODE;--更新出库单状态为 "已回执"

   select count(*) into count_all_out from scm_outstore s where instr(outstorecode,s.outcode,1)>0;--配送单上的出库单数量
   select count(*) into count_in_isdn from scm_outstore s1 where instr(outstorecode,s1.outcode,1)>0 and s1.outtype=2;--已经'回执'的出库单数量

   if count_all_out=count_in_isdn then
       update scm_car c set c.car_free_status=0 where instr(carplante,c.number_plate,1)>0;--改变车辆的状态 '空闲'
   else
       update scm_psorder  set status=2 where pscode=spcode and status<>2;
   end if;
   EXCEPTION
       WHEN NO_DATA_FOUND THEN
           update scm_psorder  set status=2 where pscode=spcode and status<>2;
end;


作者: szc108   发布时间: 2011-09-06

顶楼主
向1楼学习

作者: delphisanding1   发布时间: 2011-09-06

热门下载

更多