我正在尝试从 Oracle DB 中提取两个 tkinter 日历日期内的数据,日历中的日期格式为 date_pattern='yyyy-mm-dd' Oracle DB 中的日期是日期时间 yyyy-mm-dd hh:mm:dd,但我不断收到诸如以下错误:
-TypeError:can only concatenate str (not "Timestamp") to str
Exception in Tkinter callback
-TypeError: can only concatenate str (not "datetime.date") to
str. Exception in Tkinter callback
And the last error:
-oracledb.exceptions.DatabaseError: ORA-01861: literal does
not match format string. Exception in Tkinter callback
Fecha = self.cal1.get_date()
Fecha2=Fecha.strftime("%Y-%m-%d %H:%M:%S")
sql = " SELECT t3.DESCRIPTION as ASSET_DESCRIPTION from maximo.BTV_workorder T1 inner join maximo.BTV_PM t2 on t2.Assetnum=T1.Assetnum left join maximo.BTV_ASSET t3 on T1.ASSETNUM=t3.ASSETNUM where T1.istask='1' and T1.SITEID='ALBAL' and T1.STATUS='COMP' and t2.STATUS='ACTIVE' and t1.STATUSDATE ='" + Fecha2 + "'"
您需要使用 oracle 的
TO_DATE
函数,并将 fecha2 字符串传递给该函数,假设您的 statusdate 列的类型是 DATE。请尝试以下。
fecha = self.cal1.get_date()
fecha2 = fecha.strftime("%Y-%m-%d %H:%M:%S")
sql = """
SELECT t3.DESCRIPTION AS ASSET_DESCRIPTION
FROM maximo.BTV_workorder T1
INNER JOIN maximo.BTV_PM t2 ON t2.Assetnum = T1.Assetnum
LEFT JOIN maximo.BTV_ASSET t3 ON T1.ASSETNUM = t3.ASSETNUM
WHERE T1.istask = '1'
AND T1.SITEID = 'ALBAL'
AND T1.STATUS = 'COMP'
AND t2.STATUS = 'ACTIVE'
AND T1.STATUSDATE = TO_DATE(:fecha2, 'YYYY-MM-DD HH24:MI:SS')
"""