[Python] How to insert 1 million rows into Oracle database with Python?

Discussão em 'Python' iniciado por Stack, Fevereiro 19, 2025.

  1. Stack

    Stack Membro Participativo

    I have ~100,000 to 1,000,000 rows to insert into an Oracle18c database. I'm quite new with Oracle and this order of magnitude of data. I reckon there must be some optimal way to do it, but for now I've only managed to implement a line by line insertion:

    def insertLines(connection, table_name, column_names, rows):
    cursor = connection.cursor()
    if table_exists(connection, table_name):
    for row in rows:
    sql = 'INSERT INTO {} ({}) VALUES ({})'.format(table_name, column_names, row)
    cursor.execute(sql)
    cursor.close()


    Is there some clear way in Oracle to bulk the rows to reach higher effectivity using cx_Oracle (the python Oracle library)?

    EDIT: I read the data from a CSV file.

    Continue reading...

Compartilhe esta Página