I have an Oracle Table named Consumer with 10 columns where in column# 2, 3 and 4 constitutes the primary key for it. Now, I want to insert into this table through a Pandas Dataframe using Insert...On Duplicate Key Update SQL statement.
First, I am converting any pandas NaNs or NaTs to Oracle None and then converting the Dataframe rows to tuples for insertion. If there is a primary key violation during insertion then I need to update only the last 4 columns in the table.
The code which I am using here is as follows:
df1 = df.astype(object).where(df.notnull(), None)
rows = [tuple(x) for x in df1.values]
query = """INSERT INTO CONSUMER VALUES (:1,:2,:3, :4, :5, :6, :7, :8, :9, :10) ON DUPLICATE KEY UPDATE 
                                  DT = VALUES(:7),
                                  AT = VALUES(:8),
                                  OB = VALUES(:9),
                                  UT = VALUES(:10)"""
dbcur.executemany(query, rows)
dbcon.commit()
Where DT, AT, OB and UT are the names of the last 4 columns in the table. But this is giving me the following error:
cx_Oracle.DatabaseError: ORA-00933: SQL command not properly ended
Can someone please help me in finding out and correcting whats wrong with my code? Many thanks in advance.
 
    