读书人

mysql触发器有关问题

发布时间: 2012-03-13 11:21:12 作者: rapoo

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)
结果是什么

读书人网 >Mysql

热点推荐