I am researching over the internet how to load CSV file to Oracle DB table in a faster way
Below is the way I was loading the table which as 1000 records in file and got loaded within no time.
But if there are 50,000 records it takes approx. 5 minutes to load.
Is there any faster and efficient way to load csv file to Oracle table?
My code :
import cx_Oracle
import csv
myquery='insert into TABLE (COLUMNNAME1,COLUMNNAME2,COLUMNNAME3,COLUMNNAME4,COLUMNNAME5,COLUMNNAME6) values (:1, :2, :3 ,:4,:5,:6)'
separator='|'
oracleConnection='user/password@hostIP/database'
def fileLoading(oracleconnection, file_name,myquery,separator):
try:
con = cx_Oracle.connect(oracleConnection)
print("Connection established")
reader = csv.reader(open("demp.csv", "r"), header=None,delimiter=separator)
columns = []
for line in reader:
columns.append(line)
cur = con.cursor()
for line in columns:
print("Inserting record to table")
insrt_stmt = myquery
cur.execute(insrt_stmt, line)
con.commit()
cur.close()
print("load completed")
except Exception as er:
print('ERRO:',er)
insrt_stmt = myqueryonly once outside the loop. Use only onecommitat the end. Open and close the cursor only once.