views:

4691

answers:

5

How do I get started?

+8  A: 

cx_Oracle is a Python extension module that allows access to Oracle databases and conforms to the Python database API specification.

More information is available here. Here is a sample showing how to connect and process a query.

#!/usr/bin/python

import cx_Oracle
connstr='scott/tiger'
conn = cx_Oracle.connect(connstr)
curs = conn.cursor()

curs.execute('select * from emp')
print curs.description
for row in curs:
    print row
conn.close()
Mark Harrison
+3  A: 

Extra information:

  • The complete connstr for a non-local database should could be something like [email protected]_SID'
  • You'll the oracle client installed (Instant Client might be a good choice) and your tnsnames.ora configured
morais
+4  A: 

Also, you can bypass TNS by using this as a connection string: [email protected]:1521/DATABASE_SID

+3  A: 

The Oracle Technology Network website has a lot of Python examples that would be worth reviewing.

http://www.oracle.com/technology/pub/articles/devlin-python-oracle.html

Querying best practices: http://www.oracle.com/technology/pub/articles/prez-python-queries.html

Data Parsing: http://www.oracle.com/technology/pub/articles/prez-python-dataparsing.html

Working with Times and Dates: http://www.oracle.com/technology/pub/articles/prez-python-timesanddates.html

David Aldridge
+2  A: 

I just set up cx_Oracle on windows. It was very tricky. Ultimately I needed to tweak my path variable: I needed to set ORACLE_HOME and ORACLE_BASE to C:\oracle\ora9 and C:\oracle respectively.

Also, I first downloaded cx_Oracle for Oracle 10 because I new that was the DB. But we use Oracle 9 libraries. I had to reinstall the right cx_Oracle version.

If "SQL Plus" does not work, you have environment issues to sort out.

cx_Oracle does work with Oracle's instantclient, which does not by default include SQL*Plus - so for testing purposes an additional install may be required to get SQL*Plus.
Jeffrey Kemp