python连接oracle12c

博主环境是
windows
python3.6
ORACLE12c

依赖包下载链接
依赖包中一共有两个文件,本机解压之后

第一步

pip install  whl文件路径

第二步

python
>> import sys
>> sys.path
查看\Python\\Python36\\lib\\site-packages
然后把 依赖包中的 第二个压缩包解压后的文件复制到 site-packages
![在这里插入图片描述](https://img-blog.csdnimg.cn/20191206151343651.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzMzczNjA4,size_16,color_FFFFFF,t_70)
把instantclient_12_2中的dll文件复制到 site-packages中

或者配置环境变量也可以,但是有点麻烦

把这些文件复制到,把instantclient_12_2中的dll文件复制到 site-packages中
在这里插入图片描述

windows python3.6 连接 oracle成功
在这里插入图片描述

测试代码

import cx_Oracle
db = cx_Oracle.connect('system', 'oracle', 'localhost:1521/XE')
cursor=db.cursor()
sql="select * from user20153442.emp"
cursor.execute(sql)

<cx_Oracle.Cursor on <cx_Oracle.Connection to system@localhost:1521/XE>>

result=cursor.fetchall()
for row in result:
	print(row)
cursor.close()
db.close()

(‘20159999’, ‘???9’, ‘??’, ‘20150901’, ‘-2000’, ‘-1000’, ‘111000’)
(‘20153442’, ‘???’, ‘??’, ‘20150901’, ‘-2000’, ‘-1000’, ‘???’)
(‘20150001’, ‘???01’, ‘??’, ‘20150901’, ‘-2000’, ‘-1000’, ‘111000’)
(‘20150002’, ‘???02’, ‘??’, ‘20150901’, ‘-2000’, ‘-1000’, ‘111000’)

cursor.close()
db.close()
发布了72 篇原创文章 · 获赞 1 · 访问量 3444

猜你喜欢

转载自blog.csdn.net/qq_43373608/article/details/103423435