Connecting to Oracle#

Data Science & AI Workbench enables you to connect to your Oracle database, to access data stored there without leaving the platform.

Before you can do so, you’ll need to install the following conda packages which contain the Python extension module and kernel access libraries required to connect to Oracle:


See Developing a project for information about the various ways to add packages to a project, and the implications of using each method.

You’ll also need to download the appropriate client-side files required from Oracle.

If your organization requires Workbench users to download and install the Oracle Instant Client as a package—from a secure private repository, for example—see these instructions for building an Instant Client package. Otherwise, let your Administrator know that you need them to build it, if that’s your typical workflow.

You can then use code such as this to access an Oracle database from within a notebook session:

# Import the library needed
import cx_Oracle

# Import config parser to read the .ini file setup as a secret
import configparser

# Setup the credentials
config = configparser.ConfigParser()'/var/run/secrets/user_credentials/oracle_credentials')

# Define some variables read from secret that was defined as an .ini file
username = config.get('default', 'username')
password = config.get('default', 'password')
uri = config.get('default', 'uri')
port = config.get('default', 'port')
db_name = <YOUR-DB-NAME>

# Create the connection and setup the cursor
conn = cx_Oracle.connect(f'{username}/{password}@//{uri}:{port}/{db_name}')
cur = conn.cursor()

# Example select statement and print for all results
# cur.execute("SELECT 'Hello World!' FROM dual")
# res = cur.fetchall()
# Print results
# print(res)

# Close the connection

See Storing secrets for information about adding credentials to the platform, to make them available in your projects. Any secrets you add will be available across all sessions and deployments associated with your user account.