- 安装cx_Oracle
- Python 连接oracle不仅需要安装cx_Oracle模块,还需要Oracle Client;在oracle官网上下载instantclient-basic,注意对应版本号,然后解压文件,把其中的oci.dll,oraocci12.dll,oraociei12.dll,oraons.dll(12是我下载的版本号)文件复制到Python安装目录libsite-packages下,然后再下载安装cx_Oracle模块
2.连接数据库
连接数据库有三种方式:
(1)用户名、密码和监听写在一起(user/passwd@host/orcl)
import cx_Oracle as dbconn = db.connect('user/passwd@host/orcl')
(2)用户名、密码和监听分开(‘user’,‘passwd’,'host/orcl')
import cx_Oracle as