全部。我使用python从dbf(vfp)文件加载数据到oracle db。但是,效率不好。记录7,000,000需要40分钟。只是我想减少循环,这是关键点。下面的代码:
import sys
import cx_Oracle
from dbfpy.dbf import *
dbhost=sys.argv[1]
dbport=sys.argv[2]
dbsid=sys.argv[3]
dbuser=sys.argv[4]
dbpasswd=sys.argv[5]
schema=sys.argv[6]
tbname=sys.argv[7]
vdate=sys.argv[8]
organ=0
gap=5000
tns = cx_Oracle.makedsn(dbhost,dbport,dbsid)
db = cx_Oracle.connect(dbuser,dbpasswd,tns)
execsql = 'truncate table ' + schema + '.' + tbname
cur = db.cursor()
cur.execute(execsql)
count=0
param=[];
execsql='insert into '+ schema + '.' + tbname + ' values(:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11)'
dbf = Dbf("E:\abc.dbf")
for rec in dbf:
param.append((vdate,rec['ZQ'],rec['TZ'],rec['TX'],rec['ZJ'],rec['ZJM'],rec['CQ'],rec['DH'],rec['RQ'],rec['ZZT'],rec['DXW']))
count += 1
if count >= gap:
cur.executemany(execsql,param);
db.commit()
param=[]
count = organ
if param:
cur.executemany(execsql,param);
db.commit()
cur.close()
db.close()
dbf.close()
大家可以帮我提高效率吗?