[Tutor] How can i print data from CLOB field..?
shobhan
schalla@vasoftware.com
Thu Jan 2 04:25:02 2003
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
Sorry guys,<br>
<br>
I've figured out how to print the data from CLOB column in Oracle<br>
Its dbms.lob_substr()<br>
<br>
Schalla<br>
<br>
shobhan wrote:<br>
<blockquote type="cite" cite="mid3E13EBF0.40701@vasoftware.com">
<title></title>
Hi Pythoners,<br>
<br>
<font face="Helvetica, foo, sans-serif" size="-1">I have some problem with
the script i've written here:<br>
<br>
<font color="#993300">#!/usr/bin/python<br>
import os<br>
import sys<br>
import string<br>
dbapi = __import__('cx_Oracle')<br>
import sql_utils<br>
import commands<br>
dbh = dbapi.connect("scott/tiger@mydb")<br>
dbc = dbh.cursor()<br>
<br>
<br>
dbc.execute("SELECT entry_id, span_id, start_time, depth, severity, message_type,
message, ref_message FROM log_entries")<br>
<br>
for row in dbc.fetchall():<br>
print int(row[0]), int(row[1]), int(row[2]), int(row[3]), int(row[4]),
int(row[5]), row[6], row[7]<br>
print "\n\n"<br>
dbc.close()<br>
</font></font><br>
<font face="Helvetica, foo, sans-serif" size="-1">Here the "message" and
"ref_message" are of tyoe CLOB in the oracle DB.<br>
When i execute the above script its printing the data as follows:<br>
<br>
<font color="#993300">8189 1363 1035744241 0 4 0 <ExternalLobVar
object at 0x82d98c8> <ExternalLobVar object at 0x82d98e0><br>
<br>
<font color="#000000">Can anyone tell me how to printout the data from the
CLOB column..in the above script...??<br>
<br>
Thanks in advance<br>
Schalla</font><br>
</font><br>
</font><br>
Bob Gailer wrote:<br>
<blockquote type="cite"
cite="mid5.2.0.9.0.20021231105230.01a0bb70@66.28.54.253"> 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></x-sigsep>
<p> Bob Gailer<br>
<a href="mailto:ramrom@earthling.net" eudora="autourl">mailto:ramrom@earthling.net</a><br>
303 442 2625<br>
</p>
<pre wrap=""><br><hr width="90%" size="4"><br><br>---<br>Outgoing mail is certified Virus Free.<br>Checked by AVG anti-virus system (<a
class="moz-txt-link-freetext" href="http://www.grisoft.com">http://www.grisoft.com</a>).<br>Version: 6.0.431 / Virus Database: 242 - Release Date: 12/17/2002<br></pre>
</blockquote>
<br>
<br>
</blockquote>
<br>
<br>
</body>
</html>