python oracle擴充套件安裝和資料連線

2021-06-19 07:14:47 字數 1785 閱讀 9974

window環境:

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環境:

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,(此處參考

設定環境變數

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引數,否則還會報上述錯誤

[root@bj-update-01 ~]# rpm -ivh --nodeps cx_oracle-5.0.1-10g-py24-1.x86_64.rpm 

#5.0.3版本不用加--nodeps引數

測試:

#python

>>> import cx_oracle

>>> db = cx_oracle.connect('user/[email protected]:1521/orcl')

>>> print db

>>> cr=db.cursor()

>>> cr.execute("select * from logininfo")

<__builtin__.oraclecursor on >

>>> 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 oracle使用心得

1.首先確定版本。解壓到指定目錄,加入環境變數 變數名 oracle home 變數名 tns admin 變數名 nls lang 變數名 path 在解壓的oracle目錄instantclient 11 2 network admin建立tnsnames.ora檔案,寫入連線資料庫位址 1.首...

python oracle 資料庫連線

firstly 一定要搞清楚版本 1 oracle 客戶端的版本32 or64 11g 2 python 的版本 32or 64 4 安裝oracle客戶端之後,開啟oracle客戶端中的檔案,找到 複製oci,oraocci11,oraociei11的3個dll貼上到你的py目錄的libs sit...

python oracle 環境變數 亂碼

coding utf 8 import os oracle庫位置 解決32 64位版本不一至 os.environ path r c program files oracle instantclient 12 1 os.environ path oracle編碼 解決亂碼 os.environ nl...