Home > Database > Mysql Tutorial > oracle 触发器before和after数据区别

oracle 触发器before和after数据区别

WBOY
Release: 2016-06-07 15:20:08
Original
2430 people have browsed it

oracle触发器中,一旦数据被插入了,不能使用after insert去更改已经插入的,已经存在,更改会使触发器不执行。 如果想将查询出来的数据插入到数据库中,应该先拼接好,然后before命令会将数据插入到数据库中。 create or replace trigger test before inser

oracle触发器中,一旦数据被插入了,不能使用after insert去更改已经插入的值,值已经存在,更改会使触发器不执行。

如果想将查询出来的数据插入到数据库中,应该先拼接好,然后before命令会将数据插入到数据库中。


create or replace trigger "test"

before insert on mh_task for each row


declare
      PRAGMA            AUTONOMOUS_TRANSACTION;
      task_id           mh_task.id%type ;
      hdl_empid         mh_task.hdl_empid%type ;
      xzagent           xz_agent.userid%type :=0;
      mh_buss_name      mh_task.buss_name%type;
      mh_buss_type      mh_task.buss_type%type;


begin
      task_id   := :new.id ;
      hdl_empid := :new.hdl_empid ;
      mh_buss_name := :new.buss_name;
      mh_buss_type := :new.buss_type;


begin
     if mh_buss_name is not null then
       select distinct userid into xzagent from xz_agent  where agent = hdl_empid and  branch like '%'||mh_buss_name||'%' and rownum = 1;
     end if;


      if  xzagent != 0 then
          --update mh_task set agent = xzagent where id = task_id ;
          :new.agent := xzagent;
      end if ;
      commit;
exception                          --cx 添加异常处理
      when NO_DATA_FOUND then      --
           null;
end;                              --


end  test;
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template