1、下载
https://www.oracle.com/technetwork/database/database-technologies/instant-client/downloads/index.html
下载basic rpm,sdk rpm
https://github.com/oracle/python-cx_Oracle/tree/5.3
下载5.3,配合centos6.9的python2.6.6.
2、安装
rpm -ivh oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
rpm -ivh oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm
python setup.py build
python setup.py install
2.7.x和3.x.x非常简单
pip install cx_Oracle
3、 测试
>>> import cx_Oracle
>>> dir(cx_Oracle)
['ATTR_PURITY_DEFAULT', 'ATTR_PURITY_NEW', 。。。
>>> import cx_Oracle
>>> c = cx_Oracle.connect('user/password@192.168.157.144:1521/orcl')
>>> print(c)
<cx_Oracle.Connection to user@192.168.157.144:1521/orcl>
>>> cursor = c.cursor()
>>> cursor.execute("select * from dual")
<cx_Oracle.Cursor on <cx_Oracle.Connection to JDCG@192.168.157.144:1521/orcl>>
>>> print cursor
<cx_Oracle.Cursor on <cx_Oracle.Connection to JDCG@192.168.157.144:1521/orcl>>
>>> for x in cursor:
... print x
...
('X',)
>>>