Python and Oracle (i) basic configuration ____oracle

Source: Internet
Author: User
Tags dsn

Software Environment: 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 <cx_oracle.connection to SHGXDB@192.168.0.116:1521/ORCL

#插入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:P rogramming 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.0x1.4x1.8
26574:1.5x0.9x1.2
32721:2.4x1.4x1.8
21011:1.5x0.9x1.2
07157:2.4x1.4x1.8
18646:1.5x0.9x1.8
44654:2.0x1.4x1.8
20094:1.5x0.9x1.8
15039:2.0x0.8x1.8

By the way, configure the connection with MySQL

Operating system Download Mysql-python HTTP://WWW.CODEGOOD.COM/ARCHIVES/4

The specific api:http://mysql-python.sourceforge.net/mysqldb.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.