我正在尝试这样做
startdate = "20160123"
enddate = "20160204"
cmd = "select identification_number from bug where submitted_date >= TO_DATE(:1,'dd-MON-yy') and submitted_date <= TO_DATE(:2,'dd-MON-yy')"
cursor.execute(cmd,(startdate,enddate))
我收到错误
cursor.execute(cmd,(sdate,edate))
cx_Oracle.DatabaseError: ORA-01861: literal does not match format string
我看到了有关此错误的先前线程,但没有任何解决我的问题
我不确定如何将startdate
和enddate
转换为:1
和:2
,但如果是这样,那么日期格式的问题。您正在传递YYYYMMDD
并将其转换为DD-MON-YYYY
.尝试更改它。您也缺少from
条款。
我改用了between
子句。
select identification_number
from <your_table>
where
submitted_date between
TO_DATE(:1,'YYYYMMDD') and TO_DATE(:2,'YYYYMMDD')
如果这有效,则在代码中使用相同的日期格式
startdate = "20160123"
enddate = "20160204"
cmd = "select identification_number from <your_table> where submitted_date between TO_DATE(:1,'YYYYMMDD') and TO_DATE(:2,'YYYYMMDD')"