霞浦建站公司,建设通是个什么网站,有哪些网站是免费学做网页的,wordpress定时网站地图python中连接oracle数据库使用第三方库文件cx_Oracle时遇到了各种问题#xff0c;网上查找资料调试了几天才弄好#xff0c;下面是不断调试后总结的一些经验。1.oracle客户端(Oracle Instant Client)版本需要和操作系统版本位数相同#xff0c;同时cx_Oracle官方文档(http:/…python中连接oracle数据库使用第三方库文件cx_Oracle时遇到了各种问题网上查找资料调试了几天才弄好下面是不断调试后总结的一些经验。1.oracle客户端(Oracle Instant Client)版本需要和操作系统版本位数相同同时cx_Oracle官方文档(http://cx-oracle.readthedocs.io/en/latest/installation.html)上有这样一段话Version 12.2 client libraries can connect to Oracle Database 11.2 or greater. Version 12.1 client libraries can connect to Oracle Database 10.2 or greater. Version 11.2 client libraries can connect to Oracle Database 9.2 or greater.根据安装的Oracle数据库版本选择Oracle客户端(下载地址 http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html)我安装的oracle数据库是11g版本这里的客户端库在下载客户端Oracle Instant Client时就包含在内下载好oracle客户端后在客户端目录下新建一/network/admin目录并在该目录下新建tnsnames.ora文件增加自己的数据库别名配置。示例如下1 MyDB2 (DESCRIPTION 3 (ADDRESS (PROTOCOL TCP)(HOST IP)(PORT 1521))4 (CONNECT_DATA 5 (SERVER DEDICATED)6 (SERVICE_NAME )7 )8 )注意格式要排列好MyDB为Database名,Host为IP地址, SERVICE_NAME为数据库服务器的实例名。2.安装的python版本位数也需与操作系统版本位数相同3.安装的第三方库cx_Oracle需要版本位数和操作系统相同同时与Oracle数据库对应的版本也应相同因我安装的数据库是11g所以下载的是cx_Oracle-5.3-11g.win-amd64-py3.5-2 若安装的数据库是12c则应下载相应版本cx_Oracle(地址 https://pypi.python.org/pypi/cx_Oracle/5.3)同时可能出现的其他问题在cx_Oracle官方文档中也写出了1. DPI-1047: Oracle Client library cannot be loadedCheck that Python, cx_Oracle and your Oracle Client libraries are all 64-bit or all 32-bit. The DPI-1047 message will tell you whether the 64-bit or 32-bit Oracle Client is needed for your Python.检查python,cx_Oracle和Oracle Instant Client版本是否一致DPI-1047 message会告诉你安装的客户端版本是否正确。2.On Windows, restart your command prompt and use set PATH to check the environment variable has the correct Oracle Client listed before any other Oracle directories.记得配置Oracle客户端的环境变量例如我的配置是 PATH: E:\oracle\instantclient_12_2;3.On Windows, use the DIR command on the directory set in PATH. Verify that OCI.DLL exists there.检查oracle客户端(instantclient)目录下存在oci.dll文件4.On Windows, check that the correct Windows Redistributables have been installed.oracle客户端libraries需要正确的Visual Studio版本具体可见(https://oracle.github.io/odpi/doc/installation.html#windows)中windows目录下On Linux, check the LD_LIBRARY_PATH environment variable contains the Oracle Client library directory.On macOS, make sure Oracle Instant Client is in ~/lib or /usr/local/lib and that you are not using the bundled Python (use Homebrew or Python.org instead).最后一切就绪程序未出错但并无输出时感觉内心有些崩溃1 importcx_Oracle23 connection cx_Oracle.Connection([email protected]:Port/SERVICE_NAME)4 cursor connection.cursor()56 try:7 cursor.execute(select 1 / 0 from dual)8 exceptcx_Oracle.DatabaseError as exc:9 error, exc.args10 print(Oracle-Error-Code:, error.code)11 print(Oracle-Error-Message:, error.message)最后查看意识到是执行了sql语句但并未进行输出在cursor.execute(select 1 / 0 from dual)下一行增加print(cursor.description)便可以看见查找到的数据库中的内容