cx_Oracle is a module for SQL access to Oracle Database from Python. Created by Oracle. It is designed to be as compliant as possible with PEP 249 (Python Database API Specification v2.0). The version of cx_Oracle as of June 1, 2020 (initially published in this article) is 7.3. It runs on Python 2.7 or later, or Python 3.5 or later. The license is the BSD license. The DB access part uses ODPI-C (Oracle Database Programming Interface for C), an Oracle Database access library for OSS C language provided by Oracle, instead of Pro * C. cx_Oracle has the following major functions.
--Basic SQL access (DML / DDL / DCL) --Execution of PL / SQL (anonymous PL / SQL, stored program) --Support for SODA (Simple Oracle Document Access, API for accessing JSON document store) --Support for XML DB (XML Type) --Support for object functions --Providing a client-side connection pool --Support for other Oracle Database functions (instance start / stop, etc.)
All are English based. -Official Documentation
An Oracle Client is required to use cx_Oracle. There is no problem with Instant Client. There is no equivalent to Thin Driver in Java. The version of Oracle Client is compatible with 11.2 and above. On the connection destination Oracle Database Server side, the version supported by the Oracle Client you are using will be available. Before testing an application that uses cx_Oracle, make sure that you can access the Oracle Database from the machine on which you want to install cx_Oracle, such as using SQL * Plus or SQL Developer.
It can be installed using a package manager like pip or conda. The following is an installation example using pip.
pip install cx_Oracle
sample01a.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import cx_Oracle # (1)
USERID = "admin"
PASSWORD = "FooBar"
DESTINATION = "atp1_low"
SQL = "select 12345 from dual"
connection = cx_Oracle.connect(USERID, PASSWORD, DESTINATION) # (2)
cursor = connection.cursor() # (3)
cursor.execute(SQL) # (4)
for row in cursor: # (5)
print(row[0]) # (6)
connection.close() # (7)
The following is an unnecessary level if you have created an application that accesses Oracle Database in other languages, but I will briefly explain each line according to the comment number in the source.
Recommended Posts