I need to export a oracle table to a csv/excel file format (along with the column headings). A solution through cx_oracle or through sqlplus welcome.
Python code from the comment:
con = cx.connect()
cur = con.cursor()
printer = cur.execute(sqlcode)
con.commit()
perhaps use csv module (from standard library):
import csv
cursor = connection.cursor() # assuming you know how to connect to your oracle db
cursor.execute('select * from table_you_want_to_turn_to_csv')
with open('output_file.csv', 'wb') as fout:
writer = csv.writer(fout)
writer.writerow([ i[0] for i in cursor.description ]) # heading row
writer.writerows(cursor.fetchall())
If you have loads of data, unroll the fetchall() into a loop.
Happy trails!
to create XLS file, use xlwt module from the python-excel project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With