0

I am trying to do this

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))

I get an error

cursor.execute(cmd,(sdate,edate))
cx_Oracle.DatabaseError: ORA-01861: literal does not match format string

I saw previous threads regarding this error but nothing solved my problem

3
  • What does :1 and :2 mean here? The to_date function expects an string as first parameter. Commented Mar 4, 2016 at 9:21
  • 1
    @Utsav - they are just positional bind variable placeholders. (There's an explanation here). Commented Mar 4, 2016 at 9:42
  • Ok. Thanks @AlexPoole Commented Mar 4, 2016 at 9:50

1 Answer 1

2

I am not sure how startdate and enddate is translated to :1 and :2 but if it does, then the issue with date format. You are passing YYYYMMDD and you casting it as DD-MON-YYYY . Try to change it. Also you are missing from clause.

And I'd used between clause instead.

select identification_number 
from <your_table>
where 
submitted_date between 
TO_DATE(:1,'YYYYMMDD') and TO_DATE(:2,'YYYYMMDD')

If this works, then use same date format in your code

startdate = "20160123"
enddate = "20160204"
cmd = "select identification_number from <your_table> where submitted_date between TO_DATE(:1,'YYYYMMDD') and TO_DATE(:2,'YYYYMMDD')"
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot. I changed all the date formats to be of one specific form and it worked
How do you use TO DATE() inside an executemany() statement?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.