From ce9384d73fbb6700073e92d4b4a0c488d0add5cf Mon Sep 17 00:00:00 2001
From: Anthony Tuininga
Install Python from python.org.
Install cx_Oracle using Quick Start cx_Oracle Installation.
Download cx_Oracle samples or create a script like the one below.
Locate your Oracle Database username and password, and the database
-connection string. The connection string is commonly of the format
-hostname/servicename
, using the hostname where the database is
-running, and the service name of the Oracle Database instance.
Substitute your username, password and connection string in the
-code. For downloaded examples, put these in SampleEnv.py
and SampleEnv.sql
, and then follow sample/README
to create the cx_Oracle sample schema.
-SQL scripts to create Oracle Database's common sample schemas can be
-found at github.com/oracle/db-sample-schemas
Run the Python script, for example:
- --python myscript.py --
- from __future__ import print_function - - import cx_Oracle - - # Connect as user "hr" with password "welcome" to the "oraclepdb" service running on this computer. - connection = cx_Oracle.connect("hr", "welcome", "localhost/orclpdb") - - cursor = connection.cursor() - cursor.execute(""" - SELECT first_name, last_name - FROM employees - WHERE department_id = :did AND employee_id > :eid""", - did = 50, - eid = 190) - for fname, lname in cursor: - print("Values:", fname, lname) -+See Quick Start cx_Oracle Installation.