http://expert.csdn.net/Expert/TopicView1.asp?id=1939139
哪位大虾解决了,两贴同时给分,共400分

解决方案 »

  1.   

    原文:
    alter trigger wei.tia_gft_yhgeda_temp after insert on
    wei.GFT_YHGEDA_TEMP
    referencing new as new_ins
    for each row
    begin
      if new_ins.c_state = 0 then
        select c_no from GFT_RANQIBIAO where c_biaoxh = new_ins.c_biaoxh and c_biaocd = new_ins.c_biaocd;
        insert into GFT_biaodetail values(new_ins.c_gebianhao,GFT_RANQIBIAO.c_no)
      end if
    end错误:
        insert into GFT_biaodetail values(new_ins.c_gebianhao,GFT_RANQIBIAO.c_no)
                                                               ^^^^^^^^^^^^^^^^^
      end if
    解决:
    你应该把前面Select的C_No保存在一个变量中,然后在后面的Insert中使用该变量!!!
      

  2.   

    我试过这样做,可是这样就会把referencing new as new_ins
    这句滤掉,我也不知是怎么回事
      

  3.   

    不会吧???我在Oracle中作了一个类似的实验没有发生错误!!!为使么要使用referencing new as new_ins直接使用New.XXXX不行吗???
      

  4.   

    老大,或者使用游标!!!
    if new_ins.c_state = 0 then
        c_Cur In( select c_no from GFT_RANQIBIAO where c_biaoxh = new_ins.c_biaoxh and c_biaocd = new_ins.c_biaocd ) Loop
        insert into GFT_biaodetail values(new_ins.c_gebianhao,c_Cur.c_no)
        End Loop
      end if
    写法上可能有错误!!!这是Oracle的写法,我不知道你使用的是什么数据库,所以我只能照猫画虎了!!!
      

  5.   

    sql server或许我也能帮上你
    呵呵
      

  6.   

    老大,要不你把所有要插入GFT_biaodetail的数据都存储在临时变量中,然后进行插入!!!
      

  7.   

    --解决了,代码如下,请哪位高手给解释一下为何这样就可以了,而上面的就不行
    alter trigger wei.tia_gft_yhgeda_temp after insert on
    wei.GFT_YHGEDA_TEMP
    referencing new as new_i
    for each row begin
      if new_i.c_state = 0 then
        insert into GFT_BiaoDetail values(new_i.c_gebianhao,(select GFT_RANQIBIAO.c_no from GFT_RANQIBIAO where
            GFT_RANQIBIAO.c_biaoxh = new_i.c_biaoxh and GFT_RANQIBIAO.c_biaocd = new_i.c_biaocd))
      end if
    end