Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect OracleDB in Python

I need to connect Oracle DB and run scripts in Python but not sure how to do it. I currently use Oracle SQL Developer to run my queries. Please help, Attached screen shot has connection details from Oracle SQL Developer. enter image description here

like image 676
Santhosh Avatar asked Mar 04 '26 20:03

Santhosh


1 Answers

In the oracle web site there is a good tutorial that helped me a lot: Tutorial: Using Python with Oracle Database 11g.

I had to import the cx_Oracle library and I write the follow code:

import cx_Oracle

connection = cx_Oracle.connect('username/password@IP:Port/DatabaseName')
cur = connection.cursor()
cur.execute('my query')
for result in cur:
    print(result)
cur.close()
connection.close()
like image 151
Jesus Peralta Avatar answered Mar 07 '26 11:03

Jesus Peralta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!