• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

mysql触发器有关问题

mysql 搞代码 7年前 (2018-05-31) 162次浏览 已收录 0个评论

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


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:mysql触发器有关问题

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址