Thursday, April 11, 2019

How can I access Oracle database from Python language using unique way ?


How can I access Oracle database from Python language?


we usually get issue while working with oracle database using python langaugae . The big issue how to connect with database .

There are many articles are available but when you run inti issue very few helps on out . 
if you are here then you issue is solved to how to connect with oracle database using python langaugae ?



* First you need to install python (in my case python version is  3.7.2)
* Install Oracle client (in my case oracle 18c)
* Update network configuration file tnanames.ora using db details 
* Stop firewall on linux (db install on linux in my case )
* Install oracle cx_Oracle  module in python using pip command as below 
* Start listener (db service) on oracle server
 

save the file as oracle_test.py

from __future__ import print_function

import cx_Oracle

# Connect as user "hr" with password "hr" to the "ind" service running on this server.
connection = cx_Oracle.connect("hr", "hr", "192.168.43.68/ind")

cursor = connection.cursor()
cursor.execute("""
    SELECT first_name, last_name
    FROM employees
    WHERE department_id = :did AND employee_id > :eid""",
    did = 55,
    eid = 180)
for fname, lname in cursor:
    print("Values:", fname, lname)


* you can upgrade pip module using below snapshot:

 

2 comments:

  1. Enjoyed reading the article above, really explains everything in detail, the article is very interesting and effective. Thank you and good luck for the upcoming articles Python Programming Training

    ReplyDelete
  2. Usually I never comment on blogs but your article is so convincing that I never stop myself to say something about it. You’re doing a great job Man learn Oracle SOA Online Training

    ReplyDelete