create trigger appInfo_trigger before update on appinfo for each row
  Begin
  insert into appinfo_record(appId)values(old.id); if new.state=6 then select id into @uiId from ui_application where package=old.pgn limit 1;//这里结果可能为null if @uiId=null or @uiId=0 then 
     insert into ui_application(name)values(old.appName); 
else 
     update ui_application set name=old.appName where id=@uiId;
end if;
end if;
end;为什么上面的触发器总是执行else下面的update,是不是我那里错误了

解决方案 »

  1.   

    if @uiId is null or ...
      

  2.   

    if @uiId is null or @uiId=0 then orif IFNULL(@uiId,0)=0 then 
      

  3.   

    一直都执行else里面的update,而且是更新全部,后面的where条件也没用
      

  4.   

    if @uiId is null or @uiId=0 or  @uiId='' then
      

  5.   

    现在else都不走了,奇怪,我的QQ408409463,那位帮忙指导一下
      

  6.   

    if xx else xx 本来就只走一个条件的
      

  7.   

    如果我不加 if @uiId is null or @uiId=0 or @uiId='' then是可以插入的,我估计就是这里错了,我怀疑我的变量使用有问题,有没有什么办法可以输出变量
      

  8.   

    在命令行下运行
    select id into @uiId from ui_application where package=old.pgn limit 1
    什么结果
      

  9.   

    select id into @uiId from ui_application where package= 修改为1个还存在的值 limit 1检查结果是否为NULL
    SELECT IFNULL(@uiId,0) 
    结果是什么
      

  10.   

    已经搞定了,谢谢大家,是我用@ 定义不行,必须拿出来单独定义在前面,可能跟mysql版本有问题,非常感谢