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.
-
1Are you asking how one interacts with an Oracle database in Python without using cx_Oracle? Incidentally, cx_Oracle is not part of the standard Python library, but it's the most commonly used Python API for interacting with Oracle. It can be used both directly, or through a higher-level API like SQLAlchemy. You're generally not going to find a way to connect to an Oracle database in Python without doing a "pip install" of some sort of database API - unless you write some really low-level code.cdub– cdub2019-06-19 15:56:29 +00:00Commented Jun 19, 2019 at 15:56
2 Answers
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)
2 Comments
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.