是否有用于连接Oracle数据库的python 3.3模块?哪个最容易使用?类似于mysql模块的东西,只适用于Oracle。
最好是版本10g,但11g会很好。
答案 0 :(得分:10)
有: cx_Oracle
# Install --> You should have oracle installed otherwise exception will be raised
pip install cx_Oracle
import cx_Oracle
con = cx_Oracle.connect('pythonhol/welcome@127.0.0.1/orcl')
print con.version
con.close()
http://www.orafaq.com/wiki/Python
http://www.oracle.com/technetwork/articles/dsl/python-091105.html
答案 1 :(得分:0)
如果您使用的是python3
pip3 install cx_Oracle
如何连接Oracle并获得Oracle时间:
#!/usr/bin/python3
#coding=utf8
# import module
import cx_Oracle
con = cx_Oracle.connect('username/password@databasename')
# create cursor
cursor = con.cursor()
# execute sql
cursor.execute('select sysdate from dual')
# fetch one data, or fetchall()
data = cursor.fetchone()
print('Database time:%s' % data)
# close cursor and oracle
cursor.close()
con.close()