Python使用cx_Oracle模塊將oracle中數(shù)據(jù)導(dǎo)出到csv文件的方法
更新時間:2015年05月16日 10:53:50 作者:秋風(fēng)秋雨
這篇文章主要介紹了Python使用cx_Oracle模塊將oracle中數(shù)據(jù)導(dǎo)出到csv文件的方法,涉及Python中cx_Oracle模塊與csv模塊操作Oracle數(shù)據(jù)庫及csv文件的相關(guān)技巧,需要的朋友可以參考下
本文實例講述了Python使用cx_Oracle模塊將oracle中數(shù)據(jù)導(dǎo)出到csv文件的方法。分享給大家供大家參考。具體實現(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()
希望本文所述對大家的Python程序設(shè)計有所幫助。
相關(guān)文章
OpenCV(python)版實現(xiàn)文本分割之水平投影法
本文主要介紹了OpenCV(python)版實現(xiàn)文本分割之水平投影法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08python網(wǎng)絡(luò)爬蟲采集聯(lián)想詞示例
這篇文章主要介紹了python網(wǎng)絡(luò)爬蟲采集聯(lián)想詞示例,需要的朋友可以參考下2014-02-02

python自動化測試selenium操作checkbox和radiobox技術(shù)
這篇文章主要為大家介紹了python自動化測試selenium核心技術(shù)操作checkbox和radiobox的示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助
2021-11-11 
對Python生成漢字字庫文字,以及轉(zhuǎn)換為文字圖片的實例詳解
今天小編就為大家分享一篇對Python生成漢字字庫文字,以及轉(zhuǎn)換為文字圖片的實例詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
2019-01-01