python连接oracle--cx_Oracle模块

参考:https://www.cnblogs.com/Mr-Simple001/p/10516148.html (搞定,感谢原博主)

1.instantclient-basic-windows.x64-11.2.0.4.0.zip(64位) --这个必须要安装
   地址1:  百度网盘下载地址:https://pan.baidu.com/s/1wuOUIT7wmnIm5iq-50fFvQ 提取码:6f8g   

           地址2:   链接:https://pan.baidu.com/s/1G3y3EOqoI8X7Z-O9h9fYTQ
                           提取码:tt8k

(地址中有vcredist_x64.exe和instantclient-basic-windows.x64-11.2.0.4.0.zip,还有个说明!)

2.Oracle 11gR2 (64位)
最好要保持Python、instantclient和Oracle位数一致(我本机安装的都是64位的)!!!

二、步骤:
2.1 把instantclient-basic-windows.x64-11.2.0.4.0.zip解压到某一目录并把目录配置到系统环境变量Path中
2.2 下载安装vcredist_x64.exe,安装好后重启电脑,必须要重启一下
2.3 安装cx_Oracle: pip install cx_Oracle

2.4 pycharm中执行样例:

import cx_Oracle
class My_plsq:
    def my_cha(self,my_sql_c):
        try:
            conn = cx_Oracle.connect("用户名/密码@127.0.0.1:1521/orcl")  #  conn = cx_Oracle.connect("连接名","密码","localhost/orcl")
            cursor = conn.cursor()
            cursor.execute(my_sql_c)
            all_data = cursor.fetchall()
            return all_data
        except Exception as e:
            return print("执行出错了!",e)
if __name__ == '__main__':
    a=My_plsq()
    l=a.my_cha("SELECT * FROM cpq_config")
    print(l)



原文地址:https://www.cnblogs.com/Mezhou/p/13692375.html