Problems while inserting df values with python into Oracle db

  dataframe, list, oracle, oracle-sqldeveloper, python

I am having troubles when trying to insert data from a df into an Oracle database table, this is the error: DatabaseError: ORA-01036: illegal variable name/number

These are the steps I did:

This is the dataframe I have imported from yfinance package and elaborated in order to respect the integrity of the data types of my df
enter image description here

I transformed my df into a list, these are my data in the list:

enter image description here

this is the table where I want to insert my data:

enter image description here

This is the code:

sql_insert_temp = "INSERT INTO TEMPO('GIORNO','MESE','ANNO') VALUES(:2,:3,:4)"

index = 0
for i in df.iterrows():
   cursor.execute(sql_insert_temp,df_list[index])
   index += 1
connection.commit()

I have tried a single insert in the sqldeveloper worksheet, using the data you can see in the list, and it worked, so I guess I have made some mistake in the code. I have seen other discussions, but I couldn’t find any solution to my problem.. Do you have any idea of how I can solve this or maybe is it possible to do this in another way?

Thank you in advance!

Source: Python Questions

LEAVE A COMMENT