GitHub - oracle/python-cx_Oracle: Obsolete Python interface to Oracle Database, now superseded by python-oracledb (original) (raw)
Python-oracledb uses the same Python DB API as cx_Oracle, and has many new features.
import getpass
import oracledb
un = 'scott'
cs = 'localhost/orclpdb1'
pw = getpass.getpass(f'Enter password for {un}@{cs}: ')
with oracledb.connect(user=un, password=pw, dsn=cs) as connection:
with connection.cursor() as cursor:
sql = 'select systimestamp from dual'
for r in cursor.execute(sql):
print(r)