Search notes:

Python library: cx_Oracle

cx_Oracle is a PEP 249 conformant library that enables Python scripts to access Oracle databases.
In the May 2022 release, cx_Oracle was renamed to python-oracledb (for example, because cx has nothing to do with Oracle Advertising and Customer Experience (CX) or to better align with the name of the Node.js node-oracledb driver).
However, it seems that there is no python-oracledb for Python 3.6 or earlier available on PyPI, so in outdated Python environments, cx_Oracle might still be useful.

Cursor attribute

The cursor object of cx_Oracle defines some attributes in addition to those specified in those specified in PEP 249:
_get_oci_attr
_set_oci_attr
arraysize also in PEP
arrayvar
bindarraysize
bindnames
bindvars
callfunc
callproc also in PEP
close
connection also in PEP
description also in PEP
execute also in PEP
executemany also in PEP
executemanyprepared
fetchall also in PEP
fetchmany also in PEP
fetchone also in PEP
fetchraw
fetchvars
getarraydmlrowcounts
getbatcherrors
getimplicitresults
inputtypehandler
lastrowid also in PEP
outputtypehandler
parse
prefetchrows
prepare
rowcount also in PEP
rowfactory
scroll also in PEP
scrollable
setinputsizes also in PEP
setoutputsize also in PEP
statement
var

Demonstration

Connecting with a proxy user, i. e. without password:
import cx_Oracle as cxora
con = cxora.connect(user='[rene]', dsn='db')
print("Database version:", con.version)
print("Current schema:  ", con.current_schema)
print("Internal name:   ", con.internal_name)
# print(dir(con))
Create a table. Note: cursor() is a method, not an attribute!
con.cursor().execute('create table tq84_cx_Oracle(a number, b varchar2(20))')
Insert some values using named bind variables:
ins = con.cursor()

sql = 'insert into tq84_cx_Oracle values (:a, :b)'

ins.execute    (sql, dict(a=  42, b='Hello world') )

ins.executemany(sql,[dict(a=  99, b='Ninety-nine'),
                     dict(a=None, b='null'       ),
                     dict(a=  -1, b='minus one'  )])
Insert more values using positional bind variables:
ins = con.cursor()
sql = 'insert into tq84_cx_Oracle values (:1, :2)'

ins.executemany(sql, [[1, 'one'  ],
                      [2, 'two'  ],
                      [3, 'three'],
                      [4, 'four' ],
                      [5, 'five' ]])
Commit the transaction:
con.commit()
Select some values:
sel = con.cursor()
sel.execute('select * from tq84_cx_Oracle where b like :b', b = '%i%')

for a, b in sel.fetchall():
    print(f'{a:>3} {b}')
Cleaning up:
con.cursor().execute('drop table tq84_cx_Oracle')
con.close()

See also

cx_Oracle and sqlalchemy

Index