Python and Oracle Database: Scripting for the Future

Python cx_Oracle logo

Contents

Preface

If you are running this tutorial in your own environment, install the required software:

  1. Python. Version 3.6 is preferred.

  2. cx_Oracle version 7.2 and the Oracle Client libraries.

  3. SQL*Plus such as from the Oracle Instant Client SQL*Plus Package.

The Advanced Queuing section requires Oracle client 12.2 or later. The SODA section requires Oracle client 18.5, or later, and Oracle Database 18 or later.

To create the schema run:

sqlplus sys/yoursyspassword@localhost/orclpdb1 as sysdba @sql/SetupSamples

Connection Information

The database connection information is set in two files:

The username is "pythonhol" with the password "welcome". The connect string is "localhost/orclpdb1". See sql/SampleEnv.sql.

It is easist to have a local pluggable database with the service 'orclpdb1' configured. If your database is not local, or has a different service, you will need to modify the connection information in db_config.py and db_config.sql.

The following sections may need adjusting, depending on how you have set up your environment.

Overview

This tutorial is an introduction to using Python with Oracle Database. It contains beginner and advanced material. Sections can be done in any order. Choose the content that interests you and your skill level.

Follow the steps in this document. The tutorial directory has scripts to run and modify. The tutorial/solutions directory has scripts with the suggested code changes.

Use the Desktop icons to start editors and terminal windows.

If you are new to Python review the Appendix: Python Primer to gain an understanding of the language.

Using Python cx_Oracle 7 with Oracle Database

Python is a popular general purpose dynamic scripting language. The cx_Oracle interface provides Python API to access Oracle Database.