Testtabelle anlegen :
CREATE TABLE person (
name VARCHAR(40),
birthday VARCHAR(40),
PRIMARY KEY (name)
);
Code: Alles auswählen
#! python3
import cx_Oracle
con = cx_Oracle.connect('user/pass@mydb/TEST')
print(con.version)
cursor = con.cursor()
# Beispieldaten
dictionary = [{'1':'Hans','2':'TESTEST'},{'1':'Frank','2':'TESTTEST2'}]
insert = "insert into person(name, birthday) values (:1, :2)"
cursor.prepare(insert)
cursor.executemany(None, dictionary)
cursor.commit()
cursor.close()
cx_Oracle.DatabaseError: ORA-01036: Variablenname/-nummer ungültig
Ich teste nun schon einige Zeit herum und habe schon mehrere Dinge versucht.
Ist das Dictionary nicht korrekt ?
Das Einfügen von einzelnen Daten funktioniert :
Code: Alles auswählen
name = 'Horst2'
birthday = 'Blaba'
insert = "insert into person(name, birthday) values (:name, :birthday)"
cursor.execute(insert, {'name': name, 'birthday': birthday})
con.commit()
con.close()
cx_oracle