create  trigger TrainingActSignUp_tri
before insert
on trainingactsignup
for each row
 
begin declare tempTgidVar int;
declare deptid int;
declare rs decimal;
declare rs_cursor cursor  for  select tgid from tgroup where fullpath like '%,,'||deptid||',,%';
set tempTgidVar=0;
set deptid=new.entityid;

open rs_cursor;

 aa: loop
fetch rs_cursor into rs;
         select count(tasu.entityid) into tempTgidVar from trainingactsignup tasu where tasu.entityid = rs
         and tasu.entitytype = 2 and tasu.taid = new.taid;
        if(tempTgidVar = 0) then
              insert into trainingactsignup  set taid=new.taid,entitytype=2,entityid=rs,isautomatism=1,creatorid=new.creatorid,createtime=new.createtime;
            
         end if;
     end loop aa;

close rs_cursor;
end;
这个触发器  在表里面添加数据是 死循环了 求解决办法!

解决方案 »

  1.   

     select tgid from tgroup where fullpath like '%,,'||deptid||',,%';这句可以执行吗
      

  2.   

    这个触发器是你插入之前执行这个触发 ,这个触发又插入!看看是不是这个原因 ,before改成after试试
      

  3.   

    在你的TRIGGER中,有对本表插入的语句,检查一下,要达到什么目的
      

  4.   

    MYSQL无法实现,你想一个INSERT插入两条记录?