本地环境
- Oracle 11g 32 位
- python 3.7.4
- windows 10 ltsc
- pycharm
准备工作
- 执行 pip install cx_Oracle 命令安装 cx_Oracle 模块
- 安装instantclient 地址:https://www.oracle.com/technetwork/database/database-technologies/instant-client/downloads/index.html 注意:Oracle是多少位的就下在多少位的instantclient ,不然连接或报类似如下错误,解决办法就是下载对应的位
DPI-1047: 64-bit Oracle Client library cannot be loaded
- 下载完之后,解压后,将该文件路径加入到 系统的path环境中即可
测试
import cx_Oracle
if __name__ == "__main__":
print("oracle数据库连接开始")
db = cx_Oracle.connect('用户名', '密码', 'ip:1521/orcl')
cr = db.cursor()
sql = "select * from HELP"
cr.execute(sql)
rs = cr.fetchall()
print(rs)