cx_Oracle
2015-06-12 09:50
204 查看
cx_Oracle
安装
[code]pip install cx_Oracle
不过我没用那个成功安装过。我找了rpm 包,
http://nchc.dl.sourceforge.net/project/cx-oracle/5.1.2/cx_Oracle-5.1.2-11g-py26-1.x86_64.rpm
然后直接rpm安装了你懂的。
不过你在python中执行import cx_Oracle时还会报找不到lib的错误
[code][root@iZ23dnwecebZ ~]# python Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import cx_Oracle Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: libclntsh.so.11.1: cannot open shared object file: No such file or directory
其实libclntsh.so.11.1这个是有的,用find 可以找到。
/data/oms/agent/core/12.1.0.2.0/instantclient/libclntsh.so.11.1
把这个目录加到/etc/ld.so.conf
[code][root@iZ23dnwecebZ ~]# cat /etc/ld.so.conf include ld.so.conf.d/*.conf /data/oms/agent/core/12.1.0.2.0/instantclient [root@iZ23dnwecebZ ~]# ldconfig
之后执行import cx_Oracle就没有问题了。
写个小的test程序去连一下oracle
[code]import cx_Oracle db = cx_Oracle.connect('system', 'oracle', '10.168.xx.xx:1521/xxx') print db.version
显示出oracle的版本号
[code][oracle@iZ23dnwecebZ ~]$ python t.py 11.2.0.4.0
使用
可以参看http://www.oracle.com/technetwork/articles/dsl/python-091105.html
fetchone,fetchall的用法和mysql的python调用差不多。我也只是用作最简单的查询。
基本用法:
[code]import cx_Oracle con = cx_Oracle.connect('pythonhol/welcome@127.0.0.1/orcl') cur = con.cursor() sql='select * from departments order by department_id' cur.execute(sql) res = cur.fetchall() for r in res print r cur.close() con.close()
拿来做简单的查询是够了。
相关文章推荐
- Oracle数据库入门——初级系列教程
- Oracle数据库入门——常用的数据字典
- Oracle数据库入门——物化视图日志结构
- Oracle数据库入门——如何根据物化视图日志快速刷新物化视图
- Oracle数据库入门——物化视图语法
- Oracle数据库入门——pctfree和pctused详解
- Oracle数据库入门——高水位线详解
- Oracle数据库入门——sql语句和函数详解
- Oracle数据库入门——目录结构
- Oracle小知识
- Oracle数据库之PL/SQL程序设计基础
- plsql连接不了oracle 64位可尝试的解决办法
- Oracle用超级管理员 创建用户并设置权限
- ImportError: No module named cx_Oracle 解决
- Oracle EBS R12 WIP Component Issue&Return Process
- oracle在schema是什么意思?
- oracle 新建用户并赋予SDE用户的权限
- Oracle学习(十四)之users表空间数据文件管理
- Oracle学习(十三)之管理表空间以及数据库闪回设置
- Oracle学习(十二)之管理临时表空间的数据文件