软件环境:Arcgis10+Python2.6+Oracle10R2+
cx_Oracle-5.1-10g.win32-py2.6.msi(http://cx-oracle./ )
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 <cx_Oracle.Connection to http://www.360doc.com/mailto:shgxdb@192.168.0.116:1521/orclorcl
#插入Bind variables in cx_Oracle
>>> curs.execute("""select gjz from sip_rjb where rownum<:emp""",{'emp':2})
<__builtin__.OracleCursor on <cx_Oracle.Connection to shgxdb@orcl116>>
>>> 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配置连接
操作系统下载MySQL-python http://www./archives/4
具体的API:http://mysql-python./MySQLdb.html