Alok Agarwal Alok Agarwal - 3 months ago 8
Python Question

Insert Python datetime to Oracle column of type DATE

I am trying to store python datetime object to ORACLE column of type date.

so far, I have used,

rpt_time = time.strftime('%Y-%m-%d %H:%M:%S') or
rpt_time = str(datetime.datetime.now())


but all are giving ORA-01843: not a valid montn

I am really confused how to insert ORACLE date type python datetime object

Answer

As far as my search shows, ORACLE can be picky on dates so this might be what you need to do.

Firstly, check the format of date you have. For example, if you have something like, 2010/01/26:11:00:00AM, then you might want to do following on your cursor execute:

insert into x
values(99, to_date('2010/01/26:11:00:00AM', 'yyyy/mm/dd:hh:mi:ssam'));
Comments