万卷书   首页 > 电脑书籍 > Linux >在Linux机器上安装运行Oracle(上)
 
Python和Oracle

  我配置了一下python(译注:一种强大,快速的面向对象的脚本语言),以测试Oracle的编程接口和网络接口 。在python中要连Oracle,需要Digital Creation(Zope应用服务器的作者)的DCOracle模块。您只需下载软件并按照指示照做就行。如果是DCOracle 1.1.0,使用Setup-8.0.4的配置,从ORACLE_LIBS变量中删去-lsocket, -lnsl, -lgen,-lelf, -laio, 和-lposix4即可,那些都是Solaris专用的。注意Redhat 5.2和6.0中安装的 python设置不全,config目录和include目录被省略,无法编译安装第三方的模块。您必须自己编译python或者下载一个合适的RPM。找python的RPM,最好的去处可能是Oliver Andrich的 Python & Linux主页。只要rpm -e --nodeps python, 然后 rpm -i python,python-dev和其他RPM即可。

  装好python后,我运行了以下的基本查询,访问Oracle。

[uche@malatesta uche]$ python
Python 1.5.1 (#1, Sep 3 1998, 22:51:17) [GCC 2.7.2.3] on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import DCOracle
>>> #connect to DB. scott/tiger are the test database username/password
>>> dbc=DCOracle.Connect("scott/tiger@sforza") #sforza is the local
Oracle
server
>>> c = dbc.cursor()
>>> c.execute("SELECT * FROM emp WHERE emp.deptno = 10")
>>> rows = c.fetchall()
>>> print rows
[(7782, 'CLARK', 'MANAGER', 7839, dbiDate('1981-06-09 00:00:00'), 2450.0,None, 10),
(7839, 'KING', 'PRESIDENT', None, dbiDate('1981-11-17 00:00:00'), 5000.0,None, 10),
(7934, 'MILLER', 'CLERK', 7782, dbiDate('1982-01-23 00:00:00'), 1300.0,None, 10)]

上一页 下一页