我正在研究一个“audit_history”表,它存储对我的“my table”表执行的更新。我的代码只处理处理密码更新的IF语句。但只要我再添加一个,就会得到1064 SQL错误。所以我猜这和我的分隔符有关(?),但我就是不能让它工作。任何帮助都会很好。谢谢。IF (NEW.password <> OLD.password)OR (NEW.password IS NOT NULL AND OLD.password IS NULL)OR (NEW.password IS NULL AND OLD.password IS NOT NULL)THENINSERT INTO myTable.audit_historyVALUES ( 'update' , NULL , NOW() , @user_id , 'user' , 'password' , OLD.password , NEW.password);END IF;IF (NEW.landline <> OLD.landline)OR (NEW.landline IS NOT NULL AND OLD.landline IS NULL)OR (NEW.landline IS NULL AND OLD.landline IS NOT NULL)THENINSERT INTO myTable.audit_historyVALUES ( 'update' , NULL , NOW() , @user_id , 'user' , 'landline' , OLD.landline , NEW.landline);END IF;我收到此错误消息:#1064-您的SQL语法有错误;请查看MySQL服务器版本对应的手册,以获取在“IF(NEW.landlineOLD.landline)”或“NEW.landline不为空,OLD.landline”的第17行使用的正确语法 最佳答案 对于多个语句,您需要开始和结束关键字BEGIN IF (NEW.password &lt;&gt; OLD.password) OR (NEW.password IS NOT NULL AND OLD.password IS NULL) OR (NEW.password IS NULL AND OLD.password IS NOT NULL) THEN INSERT INTO myTable.audit_history VALUES ( 'update' , NULL , NOW() , @user_id , 'user' , 'password' , OLD.password , NEW.password); END IF; IF (NEW.landline &lt;&gt; OLD.landline) OR (NEW.landline IS NOT NULL AND OLD.landline IS NULL) OR (NEW.landline IS NULL AND OLD.landline IS NOT NULL) THEN INSERT INTO myTable.audit_history VALUES ( 'update' , NULL , NOW() , @user_id , 'user' , 'landline' , OLD.landline , NEW.landline); END IF;END;关于mysql - MySQL触发器与多个IF语句不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22266037/
10-13 02:02