Python で Oracle に接続してみる
試した環境は、クライアントが Windows7 Pro 32 bit + Oracle Client 11.? + Python 2.6.2、 サーバは Windows2003 SR2 + Oracle 10.2.0.3 StandardOne。
http://cx-oracle.sourceforge.net/ から Oracle 10g, UNICODE, Python 2.6 の Windows x86 Installer をダウンロードしてインストール。
こんな感じで接続確認。
import cx_Oracle import sys try: connection = cx_Oracle.connect(u'user/password@sid') cursor = connection.cursor() sql = u"""Select user, pass From TABLE1""" result = cursor.execute(sql) #type(result) OracleCursor for row in result: # row is tuple print row[0] cursor.close() connection.close() except cx_Oracle.DatabaseError, exc: error, = exc.args print >> sys.stderr, "Oracle-Error-Code:", error.code print >> sys.stderr, "Oracle-Error-Message:", error.message