python 连接ORacle11g

 

 

 一,准备软件

(1)cx_Oracle

(2)instantclient

注:

(1)instantclient是Oracle客户端,plsql称为数据库第三方可视化工具,即便装了plsql也还是要装instantclient的!!!

(2)另外目前plsql的破解版只支持32位的instantclient,32位的instantclient连接64位的Oracle没有问题,但64位的Python却用不了!!!

(3)plsql连接Oracle需要配置instantclient中的tnsnames.ora,而Python连接Oracle不需要配置instantclient中的tnsnames.ora。

tnsnames.ora配置参考博文:https://blog.csdn.net/u010916338/article/details/81367551
二,版本

比如:

windows             64位

Python3.6           64位,对应Windows版本

Oracle11g           64位

instanceclient      64位,对应Windows版本(不用管Oracle是多少位)

cx_oracle             64位,对应Windows版本;且对应Python版本3.6;且对应Oracle版本11g
三,下载地址

instantclient-basic-windows.x64-11.2.0.4.0.zip

https://www.oracle.com/technetwork/cn/database/features/instant-client/index-092699-zhs.html

链接:https://pan.baidu.com/s/11Zy-_iMyjKCAllD-rz-VCQ
提取码:jtw9


cx_Oracle-5.3-11g.win-amd64-py3.6-2.exe

https://pypi.org/project/cx-Oracle/#files

链接:https://pan.baidu.com/s/1JD7Kip9GfrBJn8Rzn33qfg
提取码:m6kg

四,安装配置

(1)cx_Oracle-5.3-11g.win-amd64-py3.6-2.exe安装,一键到底。

(2)系统环境变量path中添加D:instantclient_11_2
五,连接测试

    import cx_Oracle as oracle
    db = oracle.connect('user/password@192.168.223.138:1521/service_name')
    user用户名;password密码;服务器地址+端口号;service_name服务名
    (注:在plsql连接Oracle的instanceclient中的tnsnames.ora中配置的有。但是Python连接Oracle不需要配置tnsnames.ora)
    cursor = db.cursor()
    cursor.execute('select *from student')
    data = cursor.fetchone()
    print(data)
    cursor.close()
    db.close()

https://zh.osdn.net/projects/sfnet_cx-oracle/releases/     for oracle cx_oracle下载地址

原文地址:https://www.cnblogs.com/ruiy/p/11727475.html