create or replace trigger auto_add_recordfor_da_ws_yjqd
  after insert on da_oa_fwgz  
  for each row
declare
  t_rq date;
  t_yjdw number(5);
  t_bh number(8);
  -- local variables here
begin
   t_rq:=to_date(to_number(:new.nian),to_number(:new.yue),to_number(new.ri))
   select csbm into t_yjdw from da_csbm
     where csmc=:new.fawenchushi;
   if t_yjdw>0 then
     select max(bh) 
     into t_bh 
     from da_ws_yjqd 
     where nd=to_number(:new.nian) and yjdw=t_yjdw and qxbm='qj';
     t_bh:=t_bh+1
     insert into da_ws_yjqd (nd,yjdw,bh,wh,zrz,wjtm,rq,fj,qxbm,xhbz)
     values (to_number(new.nian),t_yjdw,t_bh,new.fwzh,new.zrz,new.ztc,t_rq,new.path,'qj',0);
   end if;
end auto_add_recordfor_da_ws_yjqd;

解决方案 »

  1.   

    t_bh:=t_bh+1;
         insert into da_ws_yjqd (nd,yjdw,bh,wh,zrz,wjtm,rq,fj,qxbm,xhbz)
         values (to_number(:new.nian),t_yjdw,t_bh,:new.fwzh,:new.zrz,:new.ztc,t_rq,:new.path,'qj',0);
      

  2.   

    知道了,我找到了,谢谢 qiyousyc(沈阳棋友) 与: Michaelyfj(星星还是那颗星星) ,问一下Michaelyfj,你说的YES是指在触发器中不能定义变量吗?那DECLARE后面是什么?
      

  3.   

    bzszp(SongZip)兄,在触发器中可以定义变量吧,