oracle_to_excel
Posted 小咖啡
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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()
以上是关于oracle_to_excel的主要内容,如果未能解决你的问题,请参考以下文章