日期:2014-05-16  浏览次数:20858 次

mysql触发器问题

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,是不是我那里错误了


------解决方案--------------------
if @uiId is null or ...
------解决方案--------------------
if @uiId is null or @uiId=0 then 

or

if IFNULL(@uiId,0)=0 then
------解决方案--------------------
if @uiId is null or @uiId=0 or @uiId='' then
------解决方案--------------------
if xx else xx 本来就只走一个条件的
------解决方案--------------------
在命令行下运行
select id into @uiId from ui_application where package=old.pgn limit 1
什么结果
------解决方案--------------------
select id into @uiId from ui_application where package= 修改为1个还存在的值 limit 1

检查结果是否为NULL
SELECT IFNULL(@uiId,0) 
结果是什么