Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to link Oracle database in python environment

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail how to link Oracle database in python environment. The content of the article is of high quality, so Xiaobian shares it with you for reference. I hope you have a certain understanding of relevant knowledge after reading this article.

First, check your Python installation:

(base) C:\Users\yspmm>python

Python 3.7.0 (default, Jun 28 2018, 08:04:48) [MSC v.1912 64 bit (AMD64)] :: Anaconda, Inc. on win32

Type "help", "copyright", "credits" or "license" for more information.

To connect Oracle, you need to install cx_Oracle and Oracle client. According to the version and system information, find the corresponding cx_Oracle from the following address. Download address: https://pypi.python.org/pypi. Search for cx_Oracle in it. You can find the module. Its download address is https://pypi.org/project/cx_Oracle/#files. The corresponding version is shown in the following figure:

Copy the download file to the specified directory or CMD into a download file directory, as follows:

(base) C:\Users\yspmm>E:

(base) E:\>cd python37

(base) E:\python37>cd tools

(base) E:\python37\tools>dir

The volume in drive E has no label.

The serial number of the volume is 0CBF-0BCF

E:\python37\tools directory

2019/08/05 11:18 .

2019/08/05 11:18 ..

2019/08/05 11:14 187,766 cx_Oracle-7.2.1-cp37-cp37m-win_amd64.whl

1 file 187,766 bytes

2 directories 68,300,627,968 available bytes

Execute pip intall command to install, as follows:

(base) E:\python37\tools>pip install cx_Oracle-7.2.1-cp37-cp37m-win_amd64.whl

Processing e:\python37\tools\cx_oracle-7.2.1-cp37-cp37m-win_amd64.whl

Installing collected packages: cx-Oracle

Successfully installed cx-Oracle-7.2.1

Next, you need to install Oracle client. If the client computer has not installed Oracle client or software before, you need to install Windows Instant Client.

1)Download Instant Client

Address: http://www.oracle.com/technetwork/topics/winx64soft-089540.html

Choose the appropriate version to download, generally 12c can be.

2)Extract the download file to a specific directory and add that directory to windows environment variables, as follows:

Put it in a place, and then configure the environment variable, Path plus the path, as follows:

D:\Program Files (x86)\instantclient_12_2

import cx_Oracle

conn = cx_Oracle.connect('aaa/bbb@192.168.1.5:1521/xxxdg')

cursor = conn.cursor()

result=cursor.execute('select * from uc.tables')

#Get a piece of data using fetchone() method

#data=cursor.fetchone()

#Get all the data

all_data=cursor.fetchall()

print (all_data)

#Get partial data, 8 items

many_data=cursor.fetchmany(8)

print (many_data)

conn.close()

How to link Oracle database in python environment is shared here. I hope the above content can be helpful to everyone and learn more knowledge. If you think the article is good, you can share it so that more people can see it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report