Python + Oracle (2)
Wow!! I didn't think getting connected to Oracle from Python would be this easy. Came across a few hickups early on, but I'm impressed!!
One was that I had Oracle 8 client. Therefore it kept on giving me the following error
ImportError: DLL load failed: The specified procedure could not be found.
Since I had downloaded the latest cx_Oracle I needed an Oracle 9i client. The resident BOFH was kind enough to point me here here, you'll need a OTN account to down load it. Just unzip the stuff there. It comes with OCI.dll. and a number of .jar which are not needed I think.
Next problem was where to setup the tnsnames.ora file. Since it didn't pick up the one in the old net/admin dir (dumb idea) didn't work, I tried putting it in the current directory, and it worked!!!
the code snippet
One was that I had Oracle 8 client. Therefore it kept on giving me the following error
ImportError: DLL load failed: The specified procedure could not be found.
Since I had downloaded the latest cx_Oracle I needed an Oracle 9i client. The resident BOFH was kind enough to point me here here, you'll need a OTN account to down load it. Just unzip the stuff there. It comes with OCI.dll. and a number of .jar which are not needed I think.
Next problem was where to setup the tnsnames.ora file. Since it didn't pick up the one in the old net/admin dir (dumb idea) didn't work, I tried putting it in the current directory, and it worked!!!
the code snippet
import cx_Oracle
connection = cx_Oracle.connect("username", "password", "tns")
cursor = connection.cursor()
cursor.arraysize = 50
cursor.execute("""select instance_name from v$instance""")
for x in cursor.fetchall():
print x[0]
1 Comments:
At 8:51 PM, edg said…
the last print should be indented
Post a Comment
<< Home