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/test@127.0.0.1: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’, ‘熊大’, ‘男’)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值