数据库

 首页 > 数据库 > postgresql > Python程序连Oracle接数据库和简单操作

Python程序连Oracle接数据库和简单操作

分享到:
【字体:
导读:
         摘要:ConnectandrunSQLqueriestoanOracledatabasefromPython从Python连接到Oracle数据库提供了运行基本可以利用的SQL查询中地理处理任务...

Python程序连Oracle接数据库和简单操作

==================================================

Connect and run SQL queries to an Oracle database from Python
==================================================

从 Python 连接到 Oracle 数据库提供了运行基本可以利用的 SQL 查询中地理处理任务的能力。提供说明描述了如何连接到 Oracle 数据库并从 Python 脚本运行的 SQL 查询。

下载和安装合适的cx_Oracle模块

http://cx-oracle.sourceforge.net/ 


根据用户自己的python版本以及Oracle版本下载对应的信息,而且如果是安装ArcGIS Desktop自带的Python,应该下载32位程序


Download 5.1.2 released July 6, 2012

Windows x86 Installer (Oracle 10g, Python 2.6)

Windows x86 Installer (Oracle 10g, Python 2.7)

Windows x86 Installer (Oracle 10g, Python 3.2)

Windows x86 Installer (Oracle 10g, Python 3.3)

Windows x86 Installer (Oracle 11g, Python 2.6)

Windows x86 Installer (Oracle 11g, Python 2.7)

Windows x86 Installer (Oracle 11g, Python 3.2)

Windows x86 Installer (Oracle 11g, Python 3.3)

Windows amd64 Installer (Oracle 10g, Python 2.6)

Windows amd64 Installer (Oracle 10g, Python 2.7)

Windows amd64 Installer (Oracle 10g, Python 3.2)

Windows amd64 Installer (Oracle 10g, Python 3.3)

Windows amd64 Installer (Oracle 11g, Python 2.6)

Windows amd64 Installer (Oracle 11g, Python 2.7)

Windows amd64 Installer (Oracle 11g, Python 3.2)

Windows amd64 Installer (Oracle 11g, Python 3.3)

相关例子参考

//引用cx_Oracle
>>> import cx_Oracle;
//Oracle连接,输入用户名密码和网络服务名
>>> conn=cx_Oracle.connect('sde/sde@orcl_165')
//定义参数获得游标
>>> cursor=conn.cursor();
//建立一个查询语句
>>> sql="select * from owner where objectid<3"
//获得游标对象
>>> cursor.execute(sql)
<__builtin__.OracleCursor on >
//获得游标指向的rows
>>> rows =cursor.fetchall()
//循环row
>>> for row in rows:
//输出row信息
...     print row
...
(1, 100, 1, u'jobs', u'luly')
(2, 100, 2, u'jim', u'bob')

#==========================
# cx-oracle的教程    ,
#==========================     
    [简单] http://www.orafaq.com/wiki/Python
    [简单] http://codingtutorials.co.uk/blog/?p=31
    [全面]Sidekick - cx_Oracle (code paterns)系列 http://www.dbaportal.eu/?q=node/125
    [全面] http://www.oracle.com/technetwork/articles/dsl/python-091105.html
    [示例] http://code.google.com/p/cx-oracle-demos 
    [介绍]Python cx_Oracle 5.0新特性 http://www.oszx.net/archives/718
如何执行Oracle的存储过程, 并取到存储过程的out游标
http://stackoverflow.com/questions/6821372/python-oracle-passing-in-a-cursor-out-parameter

=============================================================================

Connect and run SQL queries to an SQL Server database from Python
=============================================================================

相关组件下载

相关代码参考

//Make a connection to the SQL Server database using database authentication or Windows authentication by passing in the //appropriate parameters such as the server name, user ID (UID) and password (PWD):
//Database authentication string:
con = pyodbc.connect('DRIVER={SQL Server};SERVER=Prod1SQL2008R2;DATABASE=SDE;UID=sa;PWD=sa')
//Windows authentication string:
con = pyodbc.connect('Trusted_Connection=yes', driver = '{SQL Server}',server = ‘Prod1SQL2008R2 ‘, database = ‘SDE')
//Define a parameter to access the cursor method:
cur = con.cursor()
//Create a query string:
querystring = "select * into ParcelsA from ParcelsB"
//Pass the query string into the cursor method:
cur.execute(querystring)
con.commit()

==============================================================================

Connect and run SQL queries to an PostgreSQL database from Python
===============================================================================

相关组件下载

相关参考

//Import the module in the Python script:
import psycopg2
//Make a connection to a PostgreSQL database by passing in the appropriate user/password to the following connection string:
connection = psycopg2.connect(host='prod', database='sde', user='sde', password='sde')
//Define a parameter to access the cursor method:
cursor = connection.cursor()
//Create a query string and pass to cursor method:
cursor.execute('select * from PARCELS WHERE OBJECTID < 70000')
//Create a for loop and print results
for query in cursor:
    print str(query)
-------------------------------------------------------------------------------------------------------
Python程序连Oracle接数据库和简单操作
分享到:
使用PG_ctl管理Postgresql数据库
使用PG_ctl管理Postgresql数据库 pg_ctl 名称:一个初始化,启动,停止,或控制PostgreSQL服务器的设备(命令). 用法:     pg_ctl init[db] [-D DATADIR] [-s] [-o "OPTIONS"]     pg_ctl start [-w] [-t SECS] [-D DATADIR] [-s] [-l FILENAME] [-o "OPTIONS"]          pg_ctl stop [...
Windows安装postgresql数据库
Windows安装postgresql数据库 数据库可以说是web开发中不可逃避的一种技术,最近由于django项目的需要,需要用到postgreSql,而且是在windows平台下搭建。之前从来没有用过postgreSql。用到的关系型数据库就是mysql了,非关系型数据库是mongodb,而且都是在linux或者mac的平台下面弄的。但是项目需要,没办法,只好在windo...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……