使用 python 连接 oracle 数据库;
1. 安装 python3.0;
2. 安装 cx_Oracle 模块;
3. 安装 ORACLE_CLIENT ;
(ORACLE_CLIENT 和 python 位数保持一致; 要么都安装 32 位要么都用 64 位)
导入连接 oracle 的模块
- import cx_Oracle
- # 获取连接
username = 用户名
pass = 密码
ipadd = 数据库地址
sid = 数据库实例
- conn=cx_Oracle.connect('username/pass@ipadd/sid')
- c=conn.cursor()
- sql="sql 语句"
- # 执行 sql
- x=c.execute(sql)
- # 得到结果列表
- relist = c.fetchall()
- # 循环结果列表
- for i in serlist:
- print(i)
- #如果是增删改操作需要 commit 提交才会写入到数据库
- #conn.commit()
- # 关闭连接
- c.close()
来源: http://www.bubuko.com/infodetail-2728462.html