sql >> Base de Datos >  >> RDS >> Oracle

Cómo exportar una tabla a formato csv o excel

quizás use el módulo csv (de la biblioteca estándar):

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())

Si tiene muchos datos, desenrolle fetchall() en un bucle.

¡Felices rutas!