0
dataframe_list=df.values.tolist()
Conn = pyodbc.connect('Driver={Oracle};DBQ=DB_NAME;Uid=user_Name;Pwd=xxxxxxxx')
cursor = conn.cursor()

str_query = "INSERT INTO schema.Table(Year,BRAND,Model,Color,Country,State,City,Dealer,Month,sales,Adjusted_Sales,Price,ROW_INSERTED_DATE) VALUES ('{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}',);"

for index,elem in enumerate(dataframe_list): #iterating the list using index(int)
    cursor.execute(str_query,dataframe_list[index])

I am trying to load this list into Oracle table. I'm getting the the below error

ProgrammingErrorTraceback (most recent call last)
<ipython-input-38-352f29f650d7> in <module>()
      1 for index,elem in enumerate(dataframe_list): #iterating the list using index(int)
----> 2        cursor.execute(str_query,dataframe_list[index])

ProgrammingError: ('The SQL contains 0 parameter markers, but 13 parameters were supplied', 'HY000').

I have sqlalchemy, but not able to install cx_Oracle. I can read from Oracle using pyodbc. I am looking for writing a dataframe or list (which is converted from Dataframe) to Oracle.

Ilja Everilä
  • 50,538
  • 7
  • 126
  • 127
Ramsey
  • 345
  • 2
  • 5
  • 14
  • Since you already have a DataFrame why not just use pandas' [to_sql](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_sql.html) method? – Gord Thompson Oct 23 '18 at 21:35
  • Possible duplicate of [pyodbc the sql contains 0 parameter markers but 1 parameters were supplied' 'hy000'](https://stackoverflow.com/questions/43491381/pyodbc-the-sql-contains-0-parameter-markers-but-1-parameters-were-supplied-hy0) – Ilja Everilä Oct 24 '18 at 06:48
  • You should not put quotes around (proper) placeholders. The driver handles all that for you. – Ilja Everilä Oct 24 '18 at 06:49
  • I tried using to_sql with sqlalchemy, but it throws that cx_Oracle is detected error. I am not able to install cx_Oracle. Also I tried no removing the quotes and changed the parameters to ?.After changing the parameters to ?, I got the below error. ** Error: ('HY000', 'The driver did not supply an error!')** – Ramsey Oct 24 '18 at 15:03

0 Answers0