I have a python script that inserts records into a database from a dataframe using df.apply() and a sql file. There is a date field that is being inserted, and it is formatted like this:
df['some_date'] = pd.to_datetime(df['some_date'], format='%Y-%m-%dT%H:%M:%S.%f')
if 'datetime' in df.iloc[:, i].dtypes.name:
log.debug("{col} was transformed to Oracle's date string format".format(col=df.columns[i]))
# desired Oracle format is DD-MON-RR HH12:MI:SS:
df.iloc[:, i] = df.iloc[:, i].dt.tz_convert(tz='UTC')
df.iloc[:, i] = df.iloc[:, i].dt.strftime('%d-%b-%y %I.%M.%S.%f %p')
The sql file being used to perform the insert looks like this:
insert into some_schema.some_table(..., some_date, ..., insert_date)
values (..., to_timestamp(to_char(:5), 'DD-Mon-YY HH.MI.SS.FF6 PM'), ..., trunc(sysdate, 'DD'))
I have also tried using these and had the same results:
to_timestamp(:5, 'DD-Mon-YY HH.MI.SS.FF6 PM')
to_timestamp(:5, 'DD-Mon-YY HH.MI.SS.FF PM')
For some reason, when I run this process to insert records locally, there is no issue, and records are correctly written. However, when this is run on our development server, the ORA-01830 error occurs.
'10-Aug-20 03.04.18.909028 PM' This is an example of what is being inserted.
These are some of the session informations (local and dev server session settings are the same):
('NLS_NUMERIC_CHARACTERS', '.,'), ('NLS_CALENDAR', 'GREGORIAN'), ('NLS_DATE_FORMAT', 'DD-MON-RR'), ('NLS_DATE_LANGUAGE', 'AMERICAN'), ('NLS_TIME_FORMAT', 'HH.MI.SSXFF AM'), ('NLS_TIMESTAMP_FORMAT', 'DD-MON-RR HH.MI.SSXFF AM'), ('NLS_TIME_TZ_FORMAT', 'HH.MI.SSXFF AM TZR'), ('NLS_TIMESTAMP_TZ_FORMAT', 'DD-MON-RR HH.MI.SSXFF AM TZR')