I’m trying to use pyodbc to return dates that match certain criteria from an Oracle database. For example, I want to get all the dates between January 1, 2010 and January 1, 2011.
To do this I’m doing this:
x = cursor.execute(“””select
Column from Table where OutputDate > ‘2010/01/01’ and OutputDate < ‘2011/01/01′”””
Something similar worked when I was using an Access database, but now it gives me this error:
pyodbc.DataError: (‘22007’, ‘[22007] [Microsoft][ODBC driver for Oracle][Oracle]ORA-01861: literal does not match format string (1861) (SQLExecDirectW)’)
I’m on Windows 7 and the driver I’m using is Microsoft ODBC for Oracle (which I guess is obvious from the error)
Does “literal does not match format string” mean that I can’t use < and > with dates on this database? Could anyone help me?
Thanks a lot,
Alex
Literal does not match format string means that you’re trying to compare a date and a string. Change your query to the following and it should work.
Unless of course
outputdateis not a date in which case it’s best to transfer this into a date as well for your comparisions to work.Note the
betweenoperator, which you can use in this situation.There’s a list of Oracle datatypes here; the site is good for everything.
I should add that I much prefer
cx_Oraclefor communicating with Oracle from python; though that is just personal preference.