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’, ‘熊大’, ‘男’)

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