在Linux下Python脚本进行数据抽取,请教各位大神怎么才能批量抽取。

#!/usr/bin/python

-*- coding:utf-8 -*-

import cx_Oracle
import datetime
import time
import os
from sys import *
from string import *
import tty, termios
from dbipaddr import *

if len(argv) !=2:
print "Usage: python up_bill_discount.py 统计日期[YYYYMMDD]\n"
exit()

path=os.environ["HOME"] + "/trunk/etl/ecds/output/"

starttime = datetime.datetime.now()
data_dt = '%s-%s-%s' % ( argv[1][0:4], argv[1][4:6], argv[1][6:8] )
oconn = cx_Oracle.connect("fina","fina", "192.168.10.85:1521/cbs")
acur = oconn.cursor()
acur.execute("select * from JYLS")######现在只能抽取一个表的!!!

filename = path+argv[1]+"/BILL_DISCOUNT" + replace(data_dt, '-', '') + ".txt"
file = open(filename, "w+")

bCount = 0
for a in acur:

    record = (a)

    for i in range( len(record) ):
            file.write( "%s" % record[i] )
            if i < len(record) - 1:
                    file.write(":")
            else:
                    file.write("\n")

    bCount = bCount + 1
    if bCount % 1000 == 0:
            print "贴现登记抽取已完成:%s" % bCount

file.close()
fileok = path+argv[1]+"/BILL_DISCOUNT" + replace(data_dt, '-', '') + ".ok"
fok = open( fileok, 'w+' )
fok.close()

endtime = datetime.datetime.now()

print "贴现登记抽取已完成,总共用时:%s" % (endtime-starttime)
我是该怎么修改,才能实现批量抽取几十个表的,求手动修改代码。。。

1个回答

你循环执行sql语句 查询多个表格的数据

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问