Re: [cx-oracle-users] Output to Excel/CSV
Brought to you by:
atuining
From: Hancock, D. (DHANCOCK) <DHA...@ar...> - 2010-06-07 21:44:39
|
I have used cx_OracleTools (with a DumpCSV tool included). http://cx-oracletools.sourceforge.net/README.txt Caveat: What follows is based on a version from 2006, maybe earlier. DumpCSV was great except that it wouldn't escape columns that contained commas. There are a bunch of slick tools in cx_OracleTools, but we now do as Waldemar shows below. Cheers! -- David Hancock | dha...@ar... -----Original Message----- From: Waldemar Osuch [mailto:wal...@gm...] Sent: Monday, June 07, 2010 5:26 PM To: cx-...@li... Subject: Re: [cx-oracle-users] Output to Excel/CSV 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) |