Python27 with Oracle Sample(Windows OS)
来源:互联网 发布:windows录音服务器 编辑:程序博客网 时间:2024/04/30 06:59
Install oracle client
- Download url: http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
- Extract the zip file, and configure the file path to system environment
- Restart the computer
Install python oracle driver
- Name: cx_Oracle
- Download url: https://pypi.python.org/pypi/cx_Oracle/5.2.1
- Download version: Based on which oracle version you use
Install the package
Double click the package and click Run to continue to finish installation.
Test if installed successfully
Open windows command line and type below command, if there is no error then it is success.
py>>> import cx_Oracle
Code with example
import cx_Oracledef get_connection(url): try: connection = cx_Oracle.connect(url) return connection except cx_Oracle.Error as err: print err return Nonedef query_demo1(connection): cursor = connection.cursor() cursor.execute("select * from test_table") for result in cursor: print result cursor.close() connection.close() returndef query_demo2(connection): cursor = connection.cursor() cursor.execute("select * from test_table") row = cursor.fetchone() print row row = cursor.fetchone() print row cursor.close() connection.close() returndef query_demo3(connection, sql): cursor = connection.cursor() cursor.execute(sql) res = cursor.fetchmany(numRows=3) for result in res: print result cursor.close() connection.close() returndef query_by_args(connection, sql, args): cursor = connection.cursor() cursor.prepare(sql) cursor.execute(None, args) res = cursor.fetchall() print res cursor.close() connection.close() returndef query_all(connection, sql): cursor = connection.cursor() cursor.execute(sql) res = cursor.fetchall() for result in res: print result cursor.close() connection.close() returndef call_func(connection, funcName, returnType, inputParam): cursor = connection.cursor() #cursor.callfunc('myFunc', cx_Oracle.NUMBER, ('TEST',2)) res = cursor.callfunc(funcName, returnType, inputParam) print res cursor.close() connection.close() returndef call_procedure(connection, procName, in_outParam): cursor = connection.cursor() #myVar = cursor.var(cx_Oracle.NUMBER) #in_outParam = (123, myVar) cursor.callproc(procName, in_outParam) #print myVar.getValue() cursor.close() connection.close() returnconnectionUrl = "<username>/<password>@<url>:<port>/<sid>"conn = get_connection(url=connectionUrl)if conn != None : query_demo3(connection=conn,sql="select * from test_table") conn = get_connection(url=connectionUrl) query_by_args(connection=conn,sql="select * from test_table where id = :id", args={'id':100010027300474})else: print "Connection is none"
References
http://stackoverflow.com/questions/12538238/python-module-cx-oracle-module-could-not-be-found
http://www.oracle.com/technetwork/articles/dsl/python-091105.html
0 0
- Python27 with Oracle Sample(Windows OS)
- Python2.7 with MySQL Connector/Python Sample(Windows OS)
- Dynamic Library Sample with CMake on Windows
- windows下安装python27
- virtualenv的AssertionError: Filename C:\Python27\Lib\os.py does not start with any of these pref的一些办法
- Windows 7 OS,如何Debug NDK Hello-JNI Sample程序
- oracle sample
- python27的Windows下环境搭建
- JMS sample with glassfish
- Simple Windows Service Sample
- Simple Windows Service Sample
- Windows Multithreading Sample
- [abap] [sample] ALV with subtotal
- [Sample] Playing with music file
- Sample Hips With main code
- oracle dcl sample
- oracle SAMPLE 语法应用
- Oracle DW sample
- @功能 中用到 android EditText插入字符串到光标所在位置
- maven中添加Archetype
- Divide and Conquer
- Ripple Maker
- Servlet API and JSP API
- Python27 with Oracle Sample(Windows OS)
- 遍历Map集合的两种方式
- epoll详解
- 五大常用算法之一:分治算法
- netty
- MyEclipse 2016 CI 0发布
- Android4开发入门经典 之 第一部分:Android入门基础
- 用NSURLSessionDownloadTask断点续传、后台下载、锁屏下载
- 直方图均衡化