想了解将cx_Oracle部署到各种版本的OracleClient的新动态吗?本文将为您提供详细的信息,我们还将为您解答关于cx-oracle的相关问题,此外,我们还将为您介绍关于Centos下安装c
想了解将cx_Oracle部署到各种版本的Oracle Client的新动态吗?本文将为您提供详细的信息,我们还将为您解答关于cx-oracle的相关问题,此外,我们还将为您介绍关于Centos下安装cx_Oracle、centos安装cx_Oracle、cx-oracle – cx_Oracle并远程连接到Oracle数据库、cx_Oracle - Python Interface for Oracle Database的新知识。
本文目录一览:- 将cx_Oracle部署到各种版本的Oracle Client(cx-oracle)
- Centos下安装cx_Oracle
- centos安装cx_Oracle
- cx-oracle – cx_Oracle并远程连接到Oracle数据库
- cx_Oracle - Python Interface for Oracle Database
将cx_Oracle部署到各种版本的Oracle Client(cx-oracle)
我有一些使用cx_Oracle连接到Oracle数据库的小型python应用程序。我通过使用py2exe编译这些应用程序来部署它们,在许多情况下都可以正常工作。
问题是,在需要安装此软件的许多人中没有标准的Oracle Client版本(例如9i和10g),试图让所有人都对一个Oracle
Client版本进行标准化将非常令人沮丧。目前,我将9.2客户端与cx_Oracle
4.4.1一起用于9i,因此当我py2exe时,生成的exe包含cx_Oracle 4.4.1库,并且不能与10g客户端一起使用。
我没有使用任何Oracle版本的任何特定功能,因此,除了cx_Oracle兼容性问题之外,我没有任何理由关心正在使用的客户端版本。
理想的解决方案是以某种方式编译完全独立于计算机上安装的Oracle Client的版本。
如果那不可能,我将愿意为每个主要的Oracle版本(my_app_9i.exe,my_app_10g.exe等)编译单独的exe,但是我什至找不到简单的方法来执行此操作,因为安装新的cx_Oracle会覆盖我的在旧版本中,每当我进行更改时,我都必须不断地来回交换库以编译其他版本。
欢迎任何建议或其他选择。
答案1
小编典典如果要构建多个cx_Oracle版本(例如:cx_Oracle10g,cx_Oracle11g等),则需要修改cx_Oracle
setup.py脚本。脚本的最后一步是对setup()
;的调用。第一个参数是要构建的模块的名称。您所需要做的就是将更"cx_Oracle"
改为"cx_Oracle"+ ver
,其中ver是10g
,11g
等等。创建多个脚本并对其进行硬编码,或者添加另一个参数以setup.py
动态选择它。
当然,一旦掌握了这一点,就需要一种在运行时加载正确模块的机制。为此,您需要创建自己的cx_Oracle
模块,该模块的__init__.py
文件如下所示:
try: from cx_Oracle9g import *except ImportError: try: from cx_Oracle10g import * except ImportError: try: from cx_Oracle11g import *
您需要做的就是随您的应用程序一起交付自定义cx_Oracle
模块以及正确的cx_OracleXg
模块。
或者,您可以让自定义cx_Oracle
模块动态检查每个可用的Oracle客户端库(9g,10g,11g等),然后仅导入正确的匹配cx_OracleXg
模块。在这种情况下,您只需要运送一个二进制文件,其中包含您的自定义cx_Oracle
模块以及所有cx_OracleXg
模块。
Centos下安装cx_Oracle
在客户端操作oracle时候,需要安装oracle连接客户端环境,
共需要两个 rpm 包:
下载地址分别如下:
http://cx-oracle.sourceforge.net/
http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
下载后直接使用命令分别安装
rpm -ivh XXX
rpm -ivh XXX
接着测试
import cx_Oracle
最后搞定了,OK。
centos安装cx_Oracle
1、环境
2、安装oracle客户端(我下载的rpm格式)
地址oracle客户端
3、安装
上传到服务器
(1)、yum install -y libaio
(2)、rpm -ivh oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64.rpm
(3)、安装python客户端cx_Oracle
pip3 install cx_Oracle
(4)、配置环境变量
vim /etc/profile
添加
export ORACLE_HOME=/usr/lib/oracle/12.2/client64/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME
source /etc/profile
4、验证
ps:编码问题,需要配置环境变量
os.environ['NLS_LANG'] = 'SIMPLIFIED CHInesE_CHINA.UTF8'
**官方文档移步点击查看官网各平台教程
cx-oracle – cx_Oracle并远程连接到Oracle数据库
每当我尝试指定和IP地址,它似乎是在本地。
换句话说,cx_Oracle.connect()的字符串应如何格式化为非本地数据库?
有一个以前的帖子被列为通过cx_Oracle模块连接到Oracle的答案,具有以下代码:
#!/usr/bin/python import cx_Oracle connstr='scott/tiger' conn = cx_Oracle.connect(connstr) curs = conn.cursor() curs.execute('select * from emp') print curs.description for row in curs: print row conn.close()
ip = '192.168.0.1' port = 1521 SID = 'YOURSIDHERE' dsn_tns = cx_Oracle.makedsn(ip,port,SID) db = cx_Oracle.connect('username','password',dsn_tns)
我喜欢这种方法的一个主要原因是我通常有一个TNSNAMES.ORA文件躺在某个地方,我可以检查dsn_tns对象将做正确的事情做:
print dsn_tns
并将输出与我的TNSNAMES.ORA进行比较
cx_Oracle - Python Interface for Oracle Database
cx_Oracle - Python Interface for Oracle Database
Documentation·Installation.Release Notes.Source code·Mailing list
About cx_Oracle
cx_Oracleis a Python extension module that enables access to Oracle Database. It conforms to the Python database API 2.0specificationwith a considerable number of additions and a couple of exclusions.
cx_Oracle is licensed under a BSD license which you can findhere.
cx_Oracle 6 has been tested with Python version 2.7,and with versions 3.4 and higher. You can use cx_Oracle with Oracle 11.2,12.1 and 12.2 client libraries. Oracle's standard client-server version interoperability allows connection to both older and newer databases. For example Oracle 12.2 client libraries can connect to Oracle Database 11.2 or later.
Features
-
Easily installed from PyPI.
-
Support for Python 2 and 3.
-
Support for Oracle Client 11.2,12.1 and 12.2. Oracle's standard cross-version interoperability,allows easy upgrades and connectivity to different Oracle Database versions.
-
Connect to Oracle Database 9.2,10,11 or 12 (depending on the Oracle Client version used).
-
sql and PL/sql Execution. The underlying Oracle Client libraries have significant optimizations including compressed fetch,pre-fetching,client and server result set caching,and statement caching with auto-tuning.
-
Full use of Oracle Network Service infrastructure,including encrypted network traffic and security features.
-
Extensive Oracle data type support,including large object support (CLOB and BLOB).
-
Direct binding to sql objects. One great use case is binding Python objects to Oracle Spatial SDO objects.
-
Array operations for efficient INSERT and UPDATEs.
-
Array row counts and batch error handling for array operations.
-
Fetching of large result sets.
-
REF CURSOR support.
-
Support for scrollable cursors. Go back and forth through your query results.
-
Fetch PL/sql Implicit Results. Easily return query results from PL/sql.
-
Row Prefetching. Efficient use of the network.
-
Client Result Caching. Improve performance of frequently executed look-up statements.
-
Support for Advanced Queuing. Use database notifications to build micro-service applications.
-
Continuous Query Notification. Get notified when data changes.
-
Support for Edition Based RedeFinition. Easily switch applications to use updated PL/sql logic.
-
Support for setting application context during the creation of a connection,making application Metadata more accessible to the database,including in logoN triggers.
-
End-to-end monitoring and tracing.
-
Transaction Management.
-
Session Pooling.
-
Database Resident Connection Pooling (DRCP).
-
Privileged Connections.
-
External Authentication.
-
Database startup and shutdown.
-
Oracle Database High Availability Features,such as FAN notifications and Transaction Guard support.
DB API specification exclusions: The time data type is not supported by Oracle and is therefore not implemented. The methodcursor.nextset()
is not implemented either as the DB API specification assumes an implementation of cursors that does not fit well with Oracle's implementation of cursors and implicit results. See the methodcursor.getimplicitresults()for more information.
Installation
Seecx_Oracle Installationfor detailed instructions.
-
The simplest way to install cx_Oracle is with pip:
python -m pip install cx_Oracle --upgrade
If a binary wheel package is not available onPyPIfor your platform,the source package will be used.
Note that if you download a source zip file directly from GitHub then you will also need to download anODPI-Csource zip file and extract it inside the directory called "odpi".
-
After cx_Oracle is installed,Oracle client libraries must also be installed and configured. These can be from Oracle Instant Client,from a local Oracle Database,or from a full Oracle Client installation.
If you need the libraries,download and unzip theOracle Instant Client'Basic' package for your platform and set PATH,LD_LIBRARY_PATH,or similar platform-specific library path loading environment. See theinstallation notes for ODPI-Cfor help.
Versions 11.2,12.1 and 12.2 of the Oracle Client libraries on Linux,Windows and macOS are supported. Users have also reported success with other platforms.
If you require cx_Oracle 5.3,download a Windows installer fromPyPIor usepython -m pip install cx-oracle==5.3
to install from source.
Very old versions of cx_Oracle can be found in the files section atSourceforge.
Example
from __future__ import print_function import cx_Oracle connection = cx_Oracle.connect("hr","welcome","localhost/orclpdb") cursor = connection.cursor() cursor.execute(""" SELECT first_name,last_name FROM employees WHERE department_id = :did AND employee_id > :eid""",did = 50,eid = 190) for fname,lname in cursor: print("Values:",fname,lname)
For more examples,please see thesamplesand thetest suite. You can also look at the scripts incx_OracleToolsand the modules incx_PyOracleLib.
Documentation
See thecx_Oracle DocumentationandRelease Notes.
Help
Issues and questions can be raised with the cx_Oracle community onGitHubor on themailing list.
关于将cx_Oracle部署到各种版本的Oracle Client和cx-oracle的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于Centos下安装cx_Oracle、centos安装cx_Oracle、cx-oracle – cx_Oracle并远程连接到Oracle数据库、cx_Oracle - Python Interface for Oracle Database的相关信息,请在本站寻找。
本文标签: