Customise Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorised as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.

No cookies to display.

connect to an oracle database using python?

Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
  • User AvatarKiran Dalvi
  • 27 Mar, 2022
  • 0 Comments
  • 1 Min Read

connect to an oracle database using python?

Connect to an oracle database using python?

 

Step-1:download and install Python for 64-bit Windows

-go to URL: https://www.python.org/downloads/windows/

-scroll down the list until you see Python 2.7.1 – 2010-11-27

-download Windows x86-64 MSI installer (filename: python-2.7.1.amd64.msi)

-go through the installer by accepting all the defaults. The install directory will be C:\Python

-once the installation is complete, add the following locations to the windows PATH variable: C:\Python and C:\Python\Lib\site-packages

-open a command window and launch the python interpreter by running ‘python’ on the command-line prompt

STEP-2: open a command window and launch the python interpreter by running ‘python’ on the command-line prompt

1
2
3
4
C:\Users\AHMED>python
Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

 STEP 3:Install cx_Oracle

1
python -m pip install cx_Oracle --upgrade --user

STEP 4:Python Script to connect and Run SQL Query

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
C:\Users\AHMED>python
Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
>>> conn = cx_Oracle.connect('username/abc123@xx.xxx.xxx.xx/BATCH47')
>>> ver = conn.version.split(".")
>>> print(ver)
['19', '3', '0', '0', '0']
>>> cursor = conn.cursor()
>>> query = "select count(*)from student"
>>> results = cursor.execute(query).fetchall()
>>> print(results)
[(6,)]
>>> conn.close()
>>>
>>>
>>> ^Z
 
 
C:\Users\AHMED>

Hope it Helps !