oracle 触发器的问题!

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

...全文
59 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
a392091921 2011-09-26
  • 打赏
  • 举报
回复
晕还是自己解决了,一楼写了那么多,没能解决问题啊,
我的是这样的,

if(old:字段名=条件)then
执行存储过程,()写存储过程名字即可;
end if;
就这样,很简单,害我搞半天。。。
delphisanding1 2011-09-06
  • 打赏
  • 举报
回复
顶楼主
向1楼学习
szc108 2011-09-06
  • 打赏
  • 举报
回复

参考下-也是刚刚学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;

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧