Suppose my Oracle db table myTable has 10 columns and 10 rows of data with data types like below:
Column Data_Type
1 Calendarday Date *Primary key
2 col1 ...
. .
. .
. .
10 Flag Number(1,0)
and suppose my pandas dataframe df has 2 columns and 3 rows of data:
Date Bit
2000-12-21 1
2000-12-22 1
2000-12-23 1
Dtypes are: datetime64[ns] and int64.
Basically i want to update the Flag column of myTable with values from Bit in df where Calendarday is equal to Date. So here, i just want to overwrite 3 Flag records and not the entire column or the entire table. The code i am trying is:
cur = con.cursor()
query = '''insert into myTable (Calendarday, Flag) values (%s, %s);'''
cur.executemany(query, df[['Date', 'Bit']].values.tolist())
con.commit()
But executing this is giving me error:
cur.executemany(query, df[['Date', 'Bit']].values.tolist())
cx_Oracle.DatabaseError: ORA-01036: illegal variable name/number
I really don't know how to fix it. Do I need to specify the position of columns in myTable or could it be because of date format conversion issue between pandas and Oracle? Please skip suggesting sqlalchemy solutions. Need to do this the cursor way only. Any help would be sincerely appreciated.