python安裝oracle擴展及數(shù)據(jù)庫連接方法
本文實例講述了python安裝oracle擴展及數(shù)據(jù)庫連接方法。分享給大家供大家參考,具體如下:
下載:
cx_Oracle下載地址:http://cx-oracle.sourceforge.net/
instantclient-basic下載地址:http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
window環(huán)境:
python27 oracle10
需要軟件:
cx_Oracle-5.1.2-10g.win32-py2.7.msi
instantclient-basic-win32-10.2.0.4.zip
1. 直接雙擊msi文件,即安裝cx_Oracle;
2. 解壓instantclient-basic-win32-10.2.0.4.zip,將得到的.dll文件全部拷貝到F:\Python27\Lib\site-packages目錄下
linux環(huán)境:
python26 orracle10
需要軟件:
cx_Oracle-5.1.2-10g-py26-1.x86_64.rpm
basic-10.2.0.4.0-linux-x86_64.zip
1. rpm -ivh cx_Oracle-5.1.2-10g-py26-1.x86_64.rpm
2. (此處參考http://m.fzitv.net/article/106295.htm)
設置環(huán)境變量
vi /root/.bash_profile
增加如下兩行:
export ORACLE_HOME=/usr/local/instantclient_10_2 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME
運行source /root/.bash_profile使改動生效
建立此鏈接庫的符號鏈接
cd $ORACLE_HOME ln -s libclntsh.so.x.x libclntsh.so
重新安裝cx_Oracle
注意加--nodeps參數(shù),否則還會報上述錯誤
[root@BJ-UPDATE-01 ~]# rpm -ivh --nodeps cx_Oracle-5.0.1-10g-py24-1.x86_64.rpm
#5.0.3版本不用加--nodeps參數(shù)
測試:
#Python
>>> import cx_Oracle
>>> db = cx_Oracle.connect('user/psw@114.242.113.91:1521/orcl')
>>> print db
<cx_Oracle.Connection to user@114.242.113.91:1521/orcl>
>>> cr=db.cursor()
>>> cr.execute("select * from LOGININFO")
<__builtin__.OracleCursor on <cx_Oracle.Connection to user@114.242.113.91:1521/orcl>>
>>> rs=cr.fetchall()
>>> print rs
[('40288a8542746fd90142746fdbb50001', 'cccccc', 1, 1, None, None, None), ('40288a85427474b601427474b8270001', 'eeee', 1, 1, None, None, None), ('40288a854273bce0014273bee6310002', 'dddddd', 0, 0, None, None, None), ('40288a854274532d014274532f600001', 'cccccc', 1, 1, None, None, None), ('40288a8542747c750142747c77ac0001', 'eeee', 1, 1, None, None, None), ('40288a8542744fb30142744fb5e90001', 'cccccc', 1, 1, None, None, None)]
>>>
更多關于Python相關內容感興趣的讀者可查看本站專題:《Python常見數(shù)據(jù)庫操作技巧匯總》、《Python編碼操作技巧總結》、《Python圖片操作技巧總結》、《Python數(shù)據(jù)結構與算法教程》、《Python Socket編程技巧總結》、《Python函數(shù)使用技巧總結》、《Python字符串操作技巧匯總》、《Python入門與進階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》
希望本文所述對大家Python程序設計有所幫助。
相關文章
pandas round方法保留兩位小數(shù)的設置實現(xiàn)
本文主要介紹了pandas round方法保留兩位小數(shù)的設置實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-08-08
Django 查詢數(shù)據(jù)庫返回JSON的實現(xiàn)
和前端交互全部使用JSON,如何將數(shù)據(jù)庫查詢結果轉換成JSON格式,本文就來介紹一下,感興趣的小伙伴們可以參考一下2021-08-08
學習python之編寫簡單簡單連接數(shù)據(jù)庫并執(zhí)行查詢操作
這篇文章主要介紹了學習python之編寫簡單簡單連接數(shù)據(jù)庫并執(zhí)行查詢操作,需要的朋友可以參考下2016-02-02

