Ubuntu12.10 under Python (cx_oracle) access to Oracle solutions

Source: Internet
Author: User

First step: Download and install Cx_oracle

: http://sourceforge.net/projects/cx-oracle/files/5.1.2/, download the cx_oracle RMP installation file, note that the download version is best aligned with the Oracle, Python environment, My current environment is Oracle 11g and Python2.7, so the download is cx_oracle-5.1.2-11g-py27-1.x86_64.rpm.

Do not need to press RPM to install, direct decompression to remove the cx_oracle.so file (only need this), copied to the Python environment Dist-packages directory, my machine is/usr/local/lib/python2.7/ Dist-packages/.

Decompression command:

file. rpm | Cpio-div    

Step two: Download and install the Oracle Instant Client

: http://www.oracle.com/technetwork/indexes/downloads/index.html, from the database column of the Instant client link to enter, according to the current system selection of the corresponding download, I chose instant Client for Linux x86-64

Unzip the download file oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm, actually only need the so shared library file, copy all so files to a separate path, I will copy them to/opt/ Oracle-instantclient11.2/lib.

There should be 5 files:

pwd/opt/oracle-instantclient11. 2/liblslibclntsh.so. 11.1  Libnnz11.so  libocci.so.  11.1  libociei.so  libocijdbc11.so

Step three: Check and install Libaio1

sudo Install Libaio1

Fourth Step: Configure environment variables

CD ~sudo vim. BASHRC

Put the export ld_library_path= $LD _library_path:/opt/oracle-instantclient11.2/lib This line in the inside, save the exit.

Finally: Test

$ python Import  = cx_oracle.connect (' username/[email protected]:p ort/= Conn.cursor ()

A simple application:

#!/usr/bin/python#Coding=utf-8Importcx_oracledefHello ():" "Hello cx_oracle Example: 1) Print database version information. 2) query the table data." "Conn= Cx_oracle.connect ("Codomain/[email Protected]:1521/oracle1") cur=conn.cursor ()Try:        Print "Oracle version:%s"%conn.versionPrint "Table test rows:"Cur.execute ('SELECT * FROM Test')         forRowinchcur:PrintRowfinally: Cur.close () conn.close () Hello ( )

Original Reference website:

http://www.laonan.net/blog/54/http://aofengblog.blog.163.com/blog/static/6317021201157111336764/
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.