Monday, March 11, 2013

How could you connect Oracle and Python?


#!/usr/bin/python

import os
import cx_Oracle

SQL_STMT="SELECT * FROM TABLE_NAME"

# set Oracle Environment variables in case it has not been
os.putenv('ORACLE_HOME', '/oracle/product/10.2.0/db_1')
os.putenv('LD_LIBRARY_PATH', '/oracle/product/10.2.0/db_1/lib')

connection = cx_Oracle.connect('userid/password@127.0.0.1:1521/SID')

cursor = connection.cursor()
cursor.execute(SQL_STMT)
for row in cursor:
    print row

cursor.close()
connection.close()

No comments :