win7_64版python链接Oracle详细版

win7下最高版本

点击下载对应版本python,cx_Oracle,Oracle客户端链接instantclient
python-3.8.10-embed-amd64.zip
cx_Oracle-8.1.0-cp38-cp38-win_amd64.whl
instantclient-basic-windows.x64-11.2.0.4.0.zip

无法下载的话,请用下面链接下载
https://download.csdn.net/download/Little_Matches/85574806
先双击安装python3.8.10
然后cmd下安装

pip install cx_Oracle-8.1.0-cp38-cp38-win_amd64.whl

若报DPI-1047: 64-bit Oracle Client library cannot be loaded
接下来的操作,去instantclient-basic-windows.x64-11.2.0.4.0.zip解压出来,在目录找到三个文件,分别是

oci.dll、oraocci11.dll、oraociei11.dll

然后把这些文件复制到python的安装目录 /python/Lib/site-packages 下,重启工具就ok啦

官方测试代码:


# myscript.py

import cx_Oracle

# Connect as user "hr" with password "welcome" to the "orclpdb1" service running on this computer.
# 改为自己对应的数据库账号,密码,地址,端口,数据库名称
# dsn=("地址:端口/数据库名称")
#例: dsn=("localhost:1521/orclpdb1")
connection = cx_Oracle.connect(user="hr", password="welcome",
                               dsn="localhost/orclpdb1")
# cursor 游标,用于执行sql语句
cursor = connection.cursor()
cursor.execute("""
        SELECT first_name, last_name
        FROM employees
        WHERE department_id = :did AND employee_id > :eid""",
        did = 50,
        eid = 190)
for fname, lname in cursor:
    print("Values:", fname, lname)
#一次返回所有結果集fetchall
# rs =cursor.fetchall()
# print ("print all :(%s)" %rs)

#使用完记得关闭游标和链接
cursor.close()
connection.close()

猜你喜欢

转载自blog.csdn.net/Little_Matches/article/details/125166068