意思就是当bpondation表有新增记录时,根据新增记录的字段fbreedid和fprounitid及日期判断另外一个表bmonth关于fbreedid和fprounitid的记录是否存在,如果有存在就修改bmonth表(fcarcount字段值加一,其他字段值加上bponderatin新增的相对应的字段值)否则则在bmonth表中新增一条记录。

解决方案 »

  1.   

    oralce中没有if exists这种判断语句!
    可以用select count(*) into v_num from .....where .....;
    if v_num > 0 then else end if;
    来进行判断是否有数据!
      

  2.   

    create or replace trigger tests
      before insert  on dbo.bponderation  
      for each row
     declare
     num number;
    begin
    select count(*) into num
      from bmonth,inserted
      where bmonth.fbreedid=:new.fbreedid and bmonth.fprounitid=:new.fprounitid and  
      bmonth.fmonth=to_char(sysdate,'mm') and bmonth.fyear=to_char(sysdate,'yyyy')
      if num>0 then
     update...  else
      insert into bmonth (fyear,fmonth,fcarcount,fbreedid,fprounitid,
         fnetweight,foverweight,ftax,fovermoney) values(to_char(sysdate,'yyyy'),
         to_char(sysdate,'mm'),'1',:new.fbreedid,:new.fprounitid,
        :new.fnetweight,:new.overweight,:new.taxmoney,:new.overqry );  end if;
    end;
      

  3.   

    bluelamb(bluelamb) 的应该是可以的了