简体   繁体   English

使用cx_Oracle将完整的python列表推送到oracle db

[英]pushing complete python list to oracle db using cx_Oracle

I have two list having 100 elements in each (say class_db_col , and class_id_col ). 我有两个列表,每个列表都有100个元素(例如class_db_colclass_id_col )。 I want to push all the items in class_db_col list to one column (say class_result ) present in oracle DB. 我想将class_db_col列表中的所有项目推class_result oracle DB中存在的一列(例如class_result )。

statement = 'update TRANSFERS_TXN_MT set CLASS_RESULT = :1 where id= :2'
for i in range(len(class_db_col)):
     cursor.execute(statement,(class_id_col[i],class_db_col[i]))
conn.commit() 

getting this error 得到这个错误

ORA-01484: arrays can only be bound to PL/SQL statement ORA-01484:数组只能绑定到PL / SQL语句

can anyone help me with this problem? 谁能帮助我解决这个问题?

If you have an array of tuples you can use cursor.executemany() instead. 如果您有一个元组数组,则可以改用cursor.executemany()。 It looks like you have two parallel arrays which you can create tuples out of via this code: 看起来您有两个并行数组,可以通过以下代码创建元组:

data = list(zip(class_id_col, class_db_col)) 数据=列表(zip(class_id_col,class_db_col))

This should result in an array that looks like this: 这将导致一个看起来像这样的数组:

[(1, 4), (2, 6), ..., (8, 15)] [(1、4),(2、6),...,(8、15)]

Then you can use this code: 然后,您可以使用以下代码:

cursor.executemany("update TRANSFERS_TXN_MT set CLASS_RESULT = :1 where id = :2", data) cursor.executemany(“更新TRANSFERS_TXN_MT设置CLASS_RESULT =:1,其中id =:2”,数据)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM