Python使用cx_Oracle模塊將oracle中數(shù)據(jù)導(dǎo)出到csv文件的方法
本文實(shí)例講述了Python使用cx_Oracle模塊將oracle中數(shù)據(jù)導(dǎo)出到csv文件的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
# Export Oracle database tables to CSV files # FB36 - 201007117 import sys import csv import cx_Oracle connection = raw_input("Enter Oracle DB connection (uid/pwd@database) : ") orcl = cx_Oracle.connect(connection) curs = orcl.cursor() printHeader = True # include column headers in each table output sql = "select * from tab" # get a list of all tables curs.execute(sql) for row_data in curs: if not row_data[0].startswith('BIN$'): # skip recycle bin tables tableName = row_data[0] # output each table content to a separate CSV file csv_file_dest = tableName + ".csv" outputFile = open(csv_file_dest,'w') # 'wb' output = csv.writer(outputFile, dialect='excel') sql = "select * from " + tableName curs2 = orcl.cursor() curs2.execute(sql) if printHeader: # add column headers if requested cols = [] for col in curs2.description: cols.append(col[0]) output.writerow(cols) for row_data in curs2: # add table rows output.writerow(row_data) outputFile.close()
希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。
相關(guān)文章
OpenCV(python)版實(shí)現(xiàn)文本分割之水平投影法
本文主要介紹了OpenCV(python)版實(shí)現(xiàn)文本分割之水平投影法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08python網(wǎng)絡(luò)爬蟲采集聯(lián)想詞示例
這篇文章主要介紹了python網(wǎng)絡(luò)爬蟲采集聯(lián)想詞示例,需要的朋友可以參考下2014-02-02

python實(shí)現(xiàn)微信打飛機(jī)游戲

python自動(dòng)化測(cè)試selenium操作checkbox和radiobox技術(shù)

對(duì)Python生成漢字字庫(kù)文字,以及轉(zhuǎn)換為文字圖片的實(shí)例詳解