create or replace trigger t_hepub_terminal
  before insert on hepub_terminal  
  referencing new as new old as old
  for each row
declare
  -- local variables here  a_terminalcode   varchar2(200);
  a_PK_TERMINAL_H  varchar2(20);
begin
     a_terminalcode:=:new.terminalcode;
     a_PK_TERMINAL_H:=:new.PK_TERMINAL_H;
    if length(trim(nvl(a_terminalcode,'')))=0 or  a_terminalcode is null then  --业务类型定义
    --回复短信内容定义
       ---a_terminalcode:=zhongduandaima.nextval;
       select cast(zhongduandaima.nextval as varchar2(5)) into a_terminalcode from dual;
       update hepub_terminal set terminalcode=a_terminalcode where PK_TERMINAL_H=a_PK_TERMINAL_H;
       ---and terminalcode is null;
     --任务
    end if;
end T_hepub_terminal;
这个触发器有什么问题
新增后 自增量已经加1了 但是没有写入到hepub_terminal 表中

解决方案 »

  1.   

    改成after试试。
    我也不是很懂
      

  2.   

    你触发器是对hepub_terminal这个表的,但是你触发体里又对这个表进行update 这样会引发变异表的
    如果要这样的话需要使用自治事务的你想要这个触发器实现什么功能?
    将表中PK_TERMINAL与插入的新PK_TERMINAL相等的那些行的terminalcode改成新的terminalcode?
      

  3.   


    create or replace trigger t_hepub_terminal
    before insert on hepub_terminal  
    for each row
    declare
      a_terminalcode varchar2(200);
    begin
      select to_char(zhongduandaima.nextval) into a_terminalcode from dual;
      :new.terminalcode:=a_terminalcode;
    end;
    /
      

  4.   

    create sequence HARD_SEQ
     minvalue 1
     maxvalue 9999999999999999
     start with 1
     increment by 1
     cache 20
     order;
    ------------------
    create or replace trigger DATA_PRODUCT_ID
     before insert on user.table for each row
     declare
     currentNum NUMBER(10);
     begin
     select HARD_SEQ.nextval into currentNum from dual;
     :new.ID := currentNum;
     end DATA_PRODUCT_ID;