Re: [cx-oracle-users] Output to Excel/CSV
Brought to you by:
atuining
From: Waldemar O. <wal...@gm...> - 2010-06-07 21:26:32
|
On Mon, Jun 7, 2010 at 15:17, Robert <web...@gm...> wrote: > Hi new to Python here, > I have got cx_Oracle installed and verified its working. > > Does anyone have working code that : > > 1) runs a SQL via cx_Oracle and > 2) writes the result to Excel/CSV file > > thanks > Robert Here is a pattern I use quite often 8<------------------------------------------------- import csv import cx_Oracle as dbi conn = dbi.connect('user/password@dbname') cur = conn.cursor() cur.execute('select * from tbl_name') with open('tbl_name.csv', 'wb') as fp: w = csv.writer(fp) w.writerow([d[0] for d in cur.description]) for row in cur: w.writerow(row) |