oracle_to_excel

# Export Oracle database tables to CSV files
# FB36 - 201007117
import sys
import csv
import cx_Oracle
connection ="dcm/Dcm_CbPc2@215.8.7.57:11521/dcsdb"
orcl = cx_Oracle.connect(connection)
curs = orcl.cursor()
printHeader = True # include column headers in each table output
tableName = 'DCS_RESERVED_data_CRSCB'
csv_file_dest = tableName + ".csv"
outputFile = open(csv_file_dest,'w') # 'wb'
output = csv.writer(outputFile, dialect='excel', lineterminator='\n')
sql = "select * from  DCS_RESERVED_data_CRSCB a "
curs2 = orcl.cursor()
curs2.execute(sql)
res = curs2.fetchall()
print(res)
cols = []
for col in curs2.description:
    cols.append(col[0])
    print(col[0])
output.writerow(cols)
output.writerows(res)
outputFile.close()

  

posted @ 2021-06-10 15:50  rjm123456  阅读(20)  评论(0编辑  收藏  举报