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下載地址

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM