python 连接oracle 各种问题记录
2022/3/11 19:14:50
本文主要是介绍python 连接oracle 各种问题记录,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1.一般的连接方法
即通过cx_Oracle包来实现
安装方法
pip install cx_Oracle
pyhton 连接代码
import cx_Oracle print("cx_Oracle.version:", cx_Oracle.version) host = "数据库ip" port = "1521" service_name = "pdb01" # dsn = cx_Oracle.makedsn(host, port, sid) # 通过servername的方式连接 dsn = cx_Oracle.makedsn(host,port, service_name=service_name) print(dsn) connection = cx_Oracle.connect("oracle用户名", "oracle密码", dsn) cursor = cx_Oracle.Cursor(connection) # 返回连接的游标对象 cursor.execute("select * from ac01 where aac003='whosyourdaddy") result = cursor.fetchall() print (result)
通常,你要是顺利的话,那么就可以读取到数据了。但是,请看下面
问题记录
oracle 客户端问题
这里错误的原因各种各样,只记录成功的方法
即要保证(pyhton cx_Oracle oracleclient )3个都必须是64位的。
当然也可以都32位 但是我没尝试过
cx_Oracle.DatabaseError: DPI-1047
这里问题有两个
1.cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "The specified module could not be found".
2.x_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "C:\Program Files\python\oci.dll is not the correct architecture"
这里的错误意思是 不能加载64位的oracle 客户端库,也就是你oracle的客户端弄错了。换成64位即可
并且要把客户端的dll ,copy一份到python.exe对应的目录
我这里用的是instantclient_11_2。那就把目录下的所有dll copy 到python目录
cx_Oracle.DatabaseError: DPI-1072: the Oracle Client library version is unsupported
但你完成上面的修改后,可能还会遇到这个 1072的问题。
这个问题的解决办法就是更换 instantclient 的版本。 我之前用instantclient21的时候就报这个错。
换成instantclient11之后 就成功了
这篇关于python 连接oracle 各种问题记录的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python