i want to add multiple rows to table in oracle and get back added values to python list
the returned column is the primary key and is generated on the oracle side
the code I wrote doesn't work, which is understandable, but I don't know how to write otherwise. help me please
out_id = cursor.var(cx_Oracle.NUMBER)
batch = []
for i in range(3):
batch.append({'val': i})
ins = 'INSERT INTO table (col1) VALUES (:val) RETURNING table.col2 into :out_id'
cursor.executemany(ins, batch)
print(list_out_id.getvalue())
I get an error
ORA-01036: illegal variable name/number
@e.burenina A few observations here:
out_id = cursor.var(cx_Oracle.NUMBER,arraysize=3).out_id = cursor.var(int,arraysize=3)batch.append({'val':i,'out_id':out_id})The following code should return the required values:
Note: Please ensure that you do a
connection.commit()at the end, in case you want to commit your code changes to the DBAlso make changes to the arraysize parameter based on the number of rows returned by your INSERT statement.