Python+cx_Oracle訪問oracle數據庫

E:\instantclient-basic-windows.x64-18.3.0.0.0dbru\instantclient_18_3
import cx_Oracle
ModuleNotFoundError: No module named ‘cx_Oracle’
解決辦法:pip install cx_Oracle
路徑加到環境變量path下

cx_Oracle.DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be loaded解決方法
https://www.oracle.com/technetwork/topics/winx64soft-089540.html
下載
instantclient-basic-windows.x64-18.3.0.0.0dbru.zip
安裝 路徑加到環境變量path下

import cx_Oracle #引用cx_Oracle模塊
#建立數據庫連接格式 用戶名/密碼@數據庫ip:端口/sid
db=cx_Oracle.connect(‘test/[email protected]:1521/myorcl’)
#獲取cursor
cursorMy=db.cursor()
#執行數據庫操作
sql=“select * from testTable”
cursorMy.prepare(sql)
cursorMy.execute(None)
row=cursorMy.fetchone()
print(row)
#關閉cursor
cursorMy.close()
#關閉連接
db.close()
程序執行結果 打印了從表裏獲取的一行的數據
( ‘9’, ‘熊大’, ‘男’)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章