本文介绍了MySQL存储过程(SQL执行错误#1064)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞!CREATE PROCEDURE get_scheduledMsg()BEGINDECLARE _dateformat varchar(100);SET _dateformat = SELECT DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i');SELECT * FROM studentdetails WHERE classCode IS IN (SELECT class FROM messagedetails WHERE isStatus ='1' AND datecreated = _dateformat)AND sectionCode IS IN (SELECT class FROM messagedetails WHERE isStatus ='1' AND datecreated = _dateformat);END;SQL execution error #1064. Response from database:You have an error in your SQL syntax; check the manual thatcorresponds to your MySQL server version for the right syntax to usenear 'SELECT DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i');SELECT * FROM studentdetails WHERE' at line 4推荐答案SET _dateformat = SELECT DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i'); 尝试以下代替Try the following insteadCREATE PROCEDURE get_scheduledMsg()BEGINSET @dateformat = DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i');SELECT * FROM studentdetails WHERE classCode IS IN (SELECT class FROM messagedetails WHERE isStatus ='1' AND datecreated = @dateformat)AND sectionCode IS IN (SELECT class FROM messagedetails WHERE isStatus ='1' AND datecreated = @dateformat);END; 如果您仍有问题,请尝试以下代替If you are still having issues then try the following insteadDELIMITER 我现在已经注意到你正在比较 datecreated with @dateformat 这意味着该列 varchar 表 messagedetails - 将日期/日期时间值存储在varchar列中是一个非常糟糕的主意 - 使用正确的数据类型I've now noticed that you are comparing datecreated with @dateformat which implies that that column is a varchar on table messagedetails - it is a very bad idea to store date/datetime values in varchar columns - use the proper datatype 这篇关于MySQL存储过程(SQL执行错误#1064)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-13 12:20