[Tutor] How can i dump the DB data into a text file in CSV
format
Bob Gailer
ramrom@earthling.net
Tue Dec 31 13:04:02 2002
--=======2462518=======
Content-Type: multipart/alternative; x-avg-checked=avg-ok-6633D6F; boundary="=====================_2460207==.ALT"
--=====================_2460207==.ALT
Content-Type: text/plain; x-avg-checked=avg-ok-6633D6F; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 8bit
At 03:08 PM 12/31/2002 +0530, shobhan wrote:
>Can anyone tell me how to connect to Oracle DB using Python and dump the
>data from a table called "logs" into a text file in CSV format..?
I suggest using cx_oracle (http://www.computronix.com/utilities.shtml).
import cx_Oracle
conn = cx_Oracle.connect(xxx/yyy@zzz)
c = conn.cursor()
c.execute('select 1,2, 3 from dual')
l = c.fetchall()
# now you have a list of tuples, one tuple per row.
There have been several discussions on this list regarding modules for csv
files. I have not tried it, but look at
http://tratt.net/laurie/python/asv/. "ASV is a platform independent Python
module to input, manipulate and output `simple' database storage file
formats such as CSV (Comma Seperated Value) ....". I do not take credit for
spelling here!
Bob Gailer
mailto:ramrom@earthling.net
303 442 2625
--=====================_2460207==.ALT
Content-Type: text/html; x-avg-checked=avg-ok-6633D6F; charset=us-ascii
Content-Transfer-Encoding: 8bit
<html>
<body>
At 03:08 PM 12/31/2002 +0530, shobhan wrote:<br>
<blockquote type=cite class=cite cite><font face="Helvetica, Helvetica" size=2>Can
anyone tell me how to connect to Oracle DB using Python and dump the data
from a table called "logs" into a text file in CSV
format..?</font></blockquote><br>
I suggest using cx_oracle
(<a href="http://www.computronix.com/utilities.shtml" eudora="autourl">http://www.computronix.com/utilities.shtml</a>).<br><br>
import cx_Oracle <br>
conn = cx_Oracle.connect(xxx/yyy@zzz)<br>
c = conn.cursor()<br>
c.execute('select 1,2, 3 from dual')<br>
l = c.fetchall()<br>
# now you have a list of tuples, one tuple per row.<br><br>
There have been several discussions on this list regarding modules for
csv files. I have not tried it, but look at
<a href="http://tratt.net/laurie/python/asv/" eudora="autourl">http://tratt.net/laurie/python/asv/</a>.
"ASV is a platform independent Python module to input, manipulate
and output `simple' database storage file formats such as CSV (Comma
Seperated Value) ....". I do not take credit for spelling
here!<br>
<x-sigsep><p></x-sigsep>
Bob Gailer<br>
<a href="mailto:ramrom@earthling.net" eudora="autourl">mailto:ramrom@earthling.net</a><br>
303 442 2625<br>
</body>
</html>
--=====================_2460207==.ALT--
--=======2462518=======
Content-Type: text/plain; charset=us-ascii; x-avg=cert; x-avg-checked=avg-ok-6633D6F
Content-Disposition: inline
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.431 / Virus Database: 242 - Release Date: 12/17/2002
--=======2462518=======--