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 following required software:

  1. Python (3.6 preferred but 2.7 should work)
  2. cx_Oracle (version 7 preferred but 6.3 or later should work) and Oracle Instant Client Package - Basic (version 18.3 preferred 12.2 should work)
  3. Oracle Instant Client Package - SQL*Plus.

To create the schema run:

sqlplus sys/yoursyspassword@localhost/orclpdb 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/orclpdb". See sql/SampleEnv.sql.

It is easist to have a local pluggable database with the service 'orclpdb' 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.