使用cx_Oracle将完整的python列表推送到oracle db [英] pushing complete python list to oracle db using cx_Oracle

查看:271
本文介绍了使用cx_Oracle将完整的python列表推送到oracle db的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个列表,每个列表包含100个元素(例如class_db_colclass_id_col).我想将class_db_col列表中的所有项目推送到oracle DB中存在的一列(例如class_result).

I have two list having 100 elements in each (say class_db_col, and class_id_col). I want to push all the items in class_db_col list to one column (say class_result) present in oracle DB.

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() 

遇到此错误

ORA-01484:数组只能绑定到PL/SQL语句

ORA-01484: arrays can only be bound to PL/SQL statement

有人可以帮助我解决这个问题吗?

can anyone help me with this problem?

推荐答案

如果您有一个元组数组,则可以使用cursor.executemany()代替.看起来您有两个并行数组,可以通过以下代码创建元组:

If you have an array of tuples you can use cursor.executemany() instead. It looks like you have two parallel arrays which you can create tuples out of via this code:

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

data = list(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(更新TRANSFERS_TXN_MT设置CLASS_RESULT =:1,其中id =:2",数据)

cursor.executemany("update TRANSFERS_TXN_MT set CLASS_RESULT = :1 where id = :2", data)

这篇关于使用cx_Oracle将完整的python列表推送到oracle db的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆