在mysql触发器中Contact 表设置了一个BEFORE INSERT 触发器触发器中定义了以下语句DECLARE contactable BIT1;SELECT contactable INTO contactable FROM Profile WHERE username = NEWcontact;当向Contact 中插入一行时contactable的值为null而实际上Profile中
可能是因为在Profile表中没有匹配到对应的username,导致查询结果为null。可以先确认Profile表中是否存在该username,如果存在,再检查触发器中的语句是否正确。可以尝试修改语句为:
DECLARE contactable BIT(1) DEFAULT 0;
SELECT contactable INTO contactable FROM Profile WHERE username = NEW.contact LIMIT 1;
这样在Profile表中找不到对应的username时,contactable的默认值就为0,避免了null值的出现。同时,使用LIMIT 1可以确保查询结果只返回一行。
原文地址: http://www.cveoy.top/t/topic/bwYv 著作权归作者所有。请勿转载和采集!