[英]Python cx_Oracle bind list of variables
How can I use bind parameters with variable parameters, for example I would prepare in python dynamically an insert all statement, and would like to bind it with rows of data. 如何将绑定参数与可变参数一起使用,例如,我将在python中动态准备一个insert all语句,并希望将其与数据行绑定。
INSERT ALL
INTO mytable (column1, column2, column_n) VALUES (:expr[0][0], :expr[0][1], :expr[0][n])
INTO mytable (column1, column2, column_n) VALUES (:expr[1][0], :expr[1][n], :expr[1][n])
INTO mytable (column1, column2, column_n) VALUES (:expr[n][0], :expr[n][1], :expr[n][n])
SELECT * FROM dual;
Is this possible using cx_oracle
on python? 在python上使用
cx_oracle
是否可能?
Interpreting your real question as 'how do I insert lots of data efficiently in cx_Oracle', the answer is not to use INSERT ALL. 将您的真实问题解释为“如何在cx_Oracle中有效地插入大量数据”,答案是不使用INSERT ALL。 Instead you should use executemany():
相反,您应该使用executemany():
data = [
(60, "Parent 60"),
(70, "Parent 70"),
(80, "Parent 80"),
(90, "Parent 90"),
(100, "Parent 100")
]
cursor.executemany("""
insert into ParentTable (ParentId, Description)
values (:1, :2)""", data)
This is all described in https://blogs.oracle.com/opal/efficient-and-scalable-batch-statement-execution-in-python-cx_oracle 所有这些都在https://blogs.oracle.com/opal/ficient-and-scalable-batch-statement-execution-in-python-cx_oracle中进行了描述
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.