Oracle
 sql >> Database >  >> RDS >> Oracle

Ottenere dati da un database Oracle come file CSV (o qualsiasi altro formato di testo personalizzato)

Ecco un'implementazione in Python:

import cx_Oracle, csv

orcl = cx_Oracle.connect('ohd/[email protected]')
curs = orcl.cursor()

csv_file_dest = "C:\\test.csv"

output = csv.writer(open(csv_file_dest,'wb'))

sql = "select * from parameter"

curs.execute(sql)

headers_printed = False
for row_data in curs:        
    if not headers_printed:
        cols = []
        for col in curs.description:
            cols.append(col[0])
        output.writerow(cols)
        headers_printed = True

    output.writerow(row_data)