icon Batch Starting in Next Week-Data Science with Gen AI ENROLL NOW

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
  • 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

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

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

STEP 4:Python Script to connect and Run SQL Query

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/[email protected]/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 !

Let's Talk

Find your desired career path with us!

Let's Talk

Find your desired career path with us!