python-oracle,python与oracle(一)基本配置

软件环境:Arcgis10+Python2.6+Oracle10R2+

cx_Oracle-5.1-10g.win32-py2.6.msi(http://cx-oracle.sourceforge.net/)

c:\python

>>>import arcpy

>>>import cx_Oracle

>>>orcl=cx_Oracle.connect('shgxdb','shgxdb','192.168.0.116:1521/orcl')

>>>orcl116=cx_Oracle.connect('shgxdb/shgxdb@orcl116')

>>> dir(orcl)

['__class__', '__delattr__', '__doc__', '__enter__', '__exit__', '__format__', '

__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex

__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'ac

tion', 'autocommit', 'begin', 'cancel', 'changepassword', 'client_identifier', '

clientinfo', 'close', 'commit', 'current_schema', 'cursor', 'dsn', 'encoding', '

inputtypehandler', 'maxBytesPerCharacter', 'module', 'nencoding', 'outputtypehan

dler', 'password', 'ping', 'prepare', 'register', 'rollback', 'shutdown', 'start

up', 'stmtcachesize', 'subscribe', 'tnsentry', 'unregister', 'username', 'version']

>>>orcl.dsn

>>>orcl.version

>>> curs=orcl.cursor()

>>> curs.execute('select gjz from sip_rjb where rownum=1')

<__builtin__.oraclecursor on tohttp:>

#插入Bind variables in cx_Oracle

>>> curs.execute("""select gjz from sip_rjb where rownum<:emp>

<__builtin__.oraclecursor on toshgxdb>>

>>> curs.fetchone()

(26574,)

>>> curs.fetchone()

(26574,)

>>>orcl.close()

>>>orcl116.close()

#自定义函数演示

#Author:Tony

#Date:2011/2/21

#Function:Programming of fuction

#import arcpy

#import sys

import cx_Oracle

def readLiveParams(connectString):

conn=cx_Oracle.Connection(connectString)

curs=conn.cursor()

curs.execute('select gjz,rsjcc from sip_rjb where rownum<10')

liveParams={}

for row in curs.fetchall():

param,val=row

liveParams[param]=val

return liveParams

conn.close()

>>> for i in readLiveParams('shgxdb/shgxdb@orcl116'):

...  print str(i).zfill(5),":",readLiveParams('shgxdb/shgxdb@orcl116')[i]

...

42998 : 2.0×1.4×1.8

26574 : 1.5×0.9×1.2

32721 : 2.4×1.4×1.8

21011 : 1.5×0.9×1.2

07157 : 2.4×1.4×1.8

18646 : 1.5×0.9×1.8

44654 : 2.0×1.4×1.8

20094 : 1.5×0.9×1.8

15039 : 2.0×0.8×1.8

顺便交代下与mysql配置连接

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值