Python 3.3 - Connect with Oracle database

2020-06-17 06:20发布

Is there a module for python 3.3 to connect with Oracle Databases? Which is the easiest to use? Something like the mysql module, only works with Oracle.

Preferably version 10g, but 11g will do just fine.

2条回答
我只想做你的唯一
2楼-- · 2020-06-17 07:15

There is: 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

查看更多
够拽才男人
3楼-- · 2020-06-17 07:16

if you're using python3

pip3 install cx_Oracle

How to connet oracle and get oracle time:

#!/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()
查看更多
登录 后发表回答