【发布时间】:2020-04-11 18:47:58
【问题描述】:
每次我的脚本部分运行时,我都会尝试将 db2 中的 lastupdated 时间戳设置为当前时间戳
datetimes = datetime.now()
datetime1 = datetimes.strftime("%Y-%m-%d %H:%M:%S")
datetime2 = datetime.strptime(datetime1,'%Y-%m-%d %H:%M:%S')
print(type(datetime2))
print(datetime2)
sql = "update salesorder set LASTUPDATEUSER = 'Testing' and LASTUPDATEDATETIME = ? where code ='0888' "
prepared = ibm_db.prepare(conn, sql)
returnCode = ibm_db.bind_param(prepared,1,datetime2, ibm_db.SQL_PARAM_INPUT,ibm_db.SQL_CHAR)
if returnCode == False:
print("unable to bind")
#ibm_db.execute(upstmt)
#param = param1
returnCode = ibm_db.execute(prepared)
if returnCode == False:
print("unable to execut")
运行此脚本时出现错误
Traceback (most recent call last):
File "new.py", line 27, in <module>
returnCode = ibm_db.execute(prepared)
SQLCODE=-420atement Execute Failed: [IBM][CLI Driver][DB2/LINUXX8664] SQL0420N Invalid character found in a character string argument of the function "BOOLEAN". SQLSTATE=22018
我尝试了多种解决方案,例如将日期时间作为字符串传递,但没有解决问题,这是 db2 '2020-02-21 13:37:37' 中使用的时间戳格式
如果有人可以请提供一种解决此问题的方法,这将非常有帮助
【问题讨论】:
-
请编辑您的问题以提供这些事实(不要使用 cmets,它们会丢失)。 (1) SALESORDER 表上是否有任何触发器 (2)
describe table SALESORDER的输出是什么(查看列数据类型和可空性) (3) 是什么阻止您更新为 CURRENT TIMESTAMP 值(或适当时与 GMT 偏移) 即为什么你需要传递一个值,只是让数据库从特殊寄存器中计算出时间戳。