Detailed explanation of Oracle installation and database connection methods

Y2J
Release: 2017-05-08 16:47:14
Original
2051 people have browsed it

This article mainly introduces the installation of Oracle extensions and database connection methods in Python. It analyzes in more detail the installation steps, operating techniques and precautions for downloading Oracle extensions in Python and Windows and Linux environments. Friends in need can refer to the following

The example in this article describes the installation of Oracle extension and database connection method in Python. Share it with everyone for your reference, the details are as follows:

Download:

cx_Oracle download address: cx-oracle.sourceforge.net/
instantclient-basic download address :www.oracle.com/technetwork/database/features/instant-client/index-097480.html

window environment:

python27 oracle10

Required software:

##cx_Oracle-5.1.2-10g.win32-py2.7.msiinstantclient-basic-win32-10.2 .0.4.
zip

1. Double-click the msi file directly to install cx_Oracle;

2. Unzip instantclient-basic-win32-10.2.0.4.zip , copy all the obtained .dll files to the F:\Python27\Lib\site-packages directory

linux environment:

python26 orracle10

Required software:

##cx_Oracle-5.1.2-10g-py26-1.x86_64.rpm

basic-10.2.0.4.0 -linux-x86_64.zip
1. rpm -ivh cx_Oracle-5.1.2-10g-py26-1.x86_64.rpm

2. (Refer to www.jb51.net/ here article/106295.htm)


Set environment variables

vi /root/.bash_profile
Copy after login
Add the following two lines:

export ORACLE_HOME=/usr/local/instantclient_10_2
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME
Copy after login

Run source /root/.bash_profile to make the changes take effect

Create a symbolic link to this link library

cd $ORACLE_HOME
ln -s libclntsh.so.x.x libclntsh.so
Copy after login

Reinstall cx_OracleBe careful to add the --nodeps parameter, otherwise the above error will be reported

[root@BJ-UPDATE-01 ~]# rpm -ivh -- nodeps cx_Oracle-5.0.1-10g-py24-1.x86_64.rpm

#5.0.3 version does not need to add the --nodeps parameter


Test:

#Python
>>> import cx_Oracle
>>> db = cx_Oracle.connect('user/psw@114.242.113.91:1521/orcl')
>>> print db
<cx_Oracle.Connection to user@114.242.113.91:1521/orcl>
>>> cr=db.cursor()
>>> cr.execute("select * from LOGININFO")
<builtin.OracleCursor on <cx_Oracle.Connection to user@114.242.113.91:1521/orcl>>
>>> rs=cr.fetchall()
>>> print rs
[(&#39;40288a8542746fd90142746fdbb50001&#39;, &#39;cccccc&#39;, 1, 1, None, None, None), (&#39;40288a85427474b601427474b8270001&#39;, &#39;eeee&#39;, 1, 1, None, None, None), (&#39;40288a854273bce0014273bee6310002&#39;, &#39;dddddd&#39;, 0, 0, None, None, None), (&#39;40288a854274532d014274532f600001&#39;, &#39;cccccc&#39;, 1, 1, None, None, None), (&#39;40288a8542747c750142747c77ac0001&#39;, &#39;eeee&#39;, 1, 1, None, None, None), (&#39;40288a8542744fb30142744fb5e90001&#39;, &#39;cccccc&#39;, 1, 1, None, None, None)]
>>>
Copy after login
[Related recommendations]

1.

Python free video tutorial

2.

Python object-oriented video tutorial

3.

Python Learning Manual

The above is the detailed content of Detailed explanation of Oracle installation and database connection methods. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!