python如何操作oracle数据库_Python 操作 Oracle 数据库
前言
操作系統:Window 10 64 位
RPA: IS-RPA 2020.2.0
查看 IS-RPA Python 版本
由下圖可知:
IS-RPA 安裝在 E 盤,Python 解釋器所在的目錄在 IS-RPA2020/Python 下
Python 的版本是 Python 3..6.4? 32 位
下載 cx_Oracle 第三方庫
點擊這里下載:下載鏈接
cpxx,表示適用于 Python 的版本為? xx
帶有 win32 后綴是 32 位
帶有 amd64 后綴是 64 位
舉個栗子:cx_Oracle?7.3.0?cp36?cp36m?win32.whl? 表示適用于 Python3.6 版本, 32 位
安裝 cx_Oracle 第三方庫
# 安裝
1.打開 PowerShell
2. 進入 E:\Program Files\IS-RPA2020\Python\Scripts> (這里 IS-RPA 安裝在 E 盤)
3. 輸入以下命令(這里 Oracle 第三方庫的位置在 l D:\download\) PS E:\Program Files\IS-RPA2020\Python\Scripts> ..\python.exe .\pip.exe install D:\download\cx_Oracle-7.3.0-cp36-cp36m-win32.whl
注意:選擇對應 Python 版本下載 cx_oracle 第三庫
測試連接 Python 第三方庫
conn = cx_Oracle.connect('szxy/123@localhost:1527/orcl') cursor = conn.cursor() result = cursor.execute('''select * from DEPT''') data = cursor.fetchall() print(data)
運行發生異常
cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 32-bit Oracle Client librar: "E:\Oracle\product\11.2.0\dbhome_1\bin\oci.dll is not the correct architecture". See https://oracle.github.io/odpi/doc/installation.html#windows for help
發生異常原因是:小編安裝是 Oracle 版本是 Oracle 11g 64 位的,而 Python 的版本是 32 位的。
解決方案
把?instantclient-basic-nt-11.2.0.4.0.zip 解壓,?然后將 instantclient-basic-nt-11.2.0.4.0 目錄下的? oci.dll、oraocci11.dll、oraociei11.dll 拷貝到?E:\Program Files\IS-RPA2020\Python\Lib\site-packages 目錄下
重新運行
結果集中文亂碼
# 原來的 conn = cx_Oracle.connect(g_conn_str,) # 修改后的 conn = cx_Oracle.connect(g_conn_str, encoding = "UTF-8", nencoding = "UTF-8")
再次運行
參考
總結
以上是生活随笔為你收集整理的python如何操作oracle数据库_Python 操作 Oracle 数据库的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: phpstudy mysql优化_MyS
- 下一篇: python中使用函数的优点,对于pyt