0

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.

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?

1 Answer 1

2

Interpreting your real question as 'how do I insert lots of data efficiently in cx_Oracle', the answer is not to use INSERT ALL. Instead you should use 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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.