python cx_Oracle连接oracle数据库

python3连接oracle

1.安装依赖包

pip install -i https://mirrors.aliyun.com/pypi/simple/ cx_Oracle 

2.下载instantclient-basic-windows.x64-11.2.0.4.0

解压到D盘
D:\instantclient-basic-windows.x64-11.2.0.4.0\instantclient_11_2
配置环境变量

3.将dll复制到python环境中

放在对应python版本中D:\ProgramData\Anaconda3\envs\python35\Lib\site-packages

oci.dll
oraocci11.dll
oraociei11.dll

4.使用spyder3.2.3编码测试

# -*- coding: utf-8 -*-
"""
Created on Tue Mar 17 15:24:15 2020

@author: liuyunshengsir
"""
import os
#os.environ['NLS_LANG'] = 'AMERICAN_AMERICA.AL32UTF8'
#os.environ['NLS_CHARACTERSET'] = 'AL32UTF8'



import importlib,sys
#sys.path.append('D:\\instantclient-basic-windows.x64-11.2.0.4.0\\instantclient_11_2')
importlib.reload(sys)

print( sys.path)
import cx_Oracle
conn=cx_Oracle.connect('账号/密码@IP:1521/库')

c=conn.cursor()


sql='select sysdate from dual'
x=c.execute(sql)

rows=x.fetchone()
print(rows[0])
c.close()

conn.close()

你可能感兴趣的:(python3,oracle)