1. Install Oracle “instant client” and add it to the OS PATH
note: the “Python”, “Oracle instant client” and “cx_Oracle” x32/x64 version must be the same;
2. Install “cx_Oracle” (http://sourceforge.net/projects/cx-oracle/)
3. demo
import cx_Oracle
conn = cx_Oracle.connect('userId', 'pwd', 'ip:port/service_name')
print 'connected to '
print conn.dsn
cursor = conn.cursor()
cursor.execute("select * from test")
rows = cursor.fetchall()
for row in rows:
print row
Django:
If you have DBA access, you can get the SID (used in settings.py/DATABASES/NAME) with:
select instance from V$THREAD;
If not DBA, login SQLPLUS and get SID with:
select sys_context('userenv','instance_name') from dual;
python manage.py shell >>> from django.db import connection >>> cursor = connection.cursor()
没有任何报错就说明成功了.
4. more resource
http://www.cnblogs.com/ddr888/archive/2010/05/16/1736990.html
http://migle.iteye.com/blog/683279