我是stackoverflow的新手。另外,请原谅我的英语。
我有一个关于在MySQL存储过程中使用时间戳的问题。我使用的是Python5和MySQLdb Python模块(Python2.6版)。下面是创建我的存储过程的代码:
def create_procedure_sum_shift ():
global cursor
cursor.execute("CREATE PROCEDURE `sum_shift`\
(IN s_Time DATETIME, IN e_Time DATETIME)\
BEGIN\
SET @q = concat('SELECT * FROM trig_test WHERE `t_stamp`>=',\
s_Time,' AND `t_stamp` <= ', e_Time);\
PREPARE query FROM @q;\
EXECUTE query;\
deallocate prepare query;\
END;")当我尝试创建这个proc时,一切都是正常的。但是,当我调用这个proc时,我得到了一个错误。以下是此过程的调用:
def call_sum_shift(startDate, endDate):
global cursor
cursor.execute("call sum_shift(DATE('%s'),DATE('%s'));" % (startDate, endDate))
rows = cursor.fetchall()
discr = cursor.description
return rows,discrstartDate (和endDate)我得到了这个:
time = datetime.datetime(2012, 07, 25, 8, 00, 00)
startDate = str (time)下面是一个错误:
..._mysql_exceptions.ProgrammingError:(1064,"You have an error...for the right syntax to use near '00:00:00 AND `t_stamp` <= 2012-07-25 00:00:00` at line 1)我的错误在哪里?如果可能,请给出一个在MySQL存储过程中使用“时间戳”的例子。
提前谢谢。
发布于 2012-07-29 20:03:40
使用concat,您将生成一个包含DateTime文本表示形式的查询字符串,该字符串需要包含在'中。这不是正在做的。
https://stackoverflow.com/questions/11709035
复制相似问题