Under windows python connects to the oracle database

  • 2020-06-03 07:09:47
  • OfStack

python connects to the oracle database as follows

1. First install the cx_Oracle package
2. Unzip ES8en-ES9en-ES10en. x64-11.2.0.4.0.zip to c:\oracle
3. Copy all.dll files under instantclient_11_2 to c:\python34\Lib\ ES21en-ES22en \ (copy to the corresponding ES24en-ES25en folder according to your own VERSION of python)

python connection sample code:


# -*- coding: utf-8 -*-
import cx_Oracle

conn=cx_Oracle.connect('reporter','password','localhost:1521/ORCL')
cursor=conn.cursor()
sql="select * from test"
cursor.execute(sql)
data=cursor.fetchall()
print(data)
cursor.close()
conn.commit()
conn.close()

Related articles: