1、安装cx_oracle
1、通过pip install cx_oracle 安装就行了。
2、安装oracle Instant Client
1、oracle官网下载,(注意32位和64位)
2、解压后将Instant Client添加到系统环境变量path里
3、将oci.dll,oraocci11.dll,oraociei11.dll复制到python目录下面,lib/site-packages 下
3、连接测试
db = cx_Oracle.connect(username,password,'ip:port/database') #连接数据库
print(db.version) #打印版本看看
cur = db.cursor() # 游标操作
cur.execute(sql) # 执行sql语句
rows = cur.fetchall() # 获取数据
for row in rows:
print(f"{row[0]} ,",end='')