Matt
Matt

Reputation: 31

Connecting to Oracle DB in python without using 3rd parties

I'm trying to connect to an Oracle database within a python script, I'm not allowed to use any 3rd party imports/downloads, only the python standard library, like cx_oracle, which is the only solution to this I've found. I'm not super familiar with oracle databases, could someone explain how to connect and query without using cx_oracle and things like it.

Upvotes: 1

Views: 2087

Answers (2)

Christopher Jones
Christopher Jones

Reputation: 10721

Oracle's network protocol isn't public so you need either (i) some Oracle technology installed on your computer that knows that protocol - this is cx_Oracle and Oracle Instant Client (ii) or something like Oracle's ORDS product running on the database which will let you use REST calls.

If you need to interact with an Oracle Database you could make a very strong argument that you need to install cx_Oracle and Oracle Instant Client. cx_Oracle is on PyPI so it can be installed like any other Python package you need. Instant Client needs to be installed separately, but is the Oracle product that you could be expected to require to connect to Oracle DB.

Upvotes: 0

Richard
Richard

Reputation: 3120

Sourced from the documentation:

https://cx-oracle.readthedocs.io/en/latest/installation.html#quick-start-cx-oracle-installation

Example:

import cx_Oracle

# Connect as user "hr" with password "welcome" 
# to the "oraclepdb" service running on this computer. 
connection = cx_Oracle.connect("hr", "welcome", "localhost/orclpdb")

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

Upvotes: 0

Related Questions