首页
学习
活动
专区
圈层
工具
发布

python 连接 ORACLE

参考连接:https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html#oracle-client-and-oracle-database-interoperability

1. 安装oracle客户端或者oracle软件

自行下载安装即可.

2.安装cx-oracle

2.1pip安装(linux或者windows):

代码语言:javascript
复制
python -m pip install cx_Oracle --upgrade

2.2 rpm包安装(linux)

2.2.1 需要先安装oracle实例客户端

代码语言:javascript
复制
wget  https://yum.oracle.com/repo/OracleLinux/OL7/developer/x86_64/getPackage/oracle-instantclient18.3-basic-18.3.0.0.0-2.x86_64.rpm 
yum install oracle-instantclient18.3-basic-18.3.0.0.0-2.x86_64.rpm -y

2.2.2 下载并安装cx-oracle

代码语言:javascript
复制
wget https://yum.oracle.com/repo/OracleLinux/OL7/developer/x86_64/getPackage/python-cx_Oracle-7.3-1.el7.x86_64.rpm
yum install -y python-cx_Oracle-7.3-1.el7.x86_64.rpm

3.测试:

创建测试表:

代码语言:javascript
复制
create table test_python(id number, name varchar2(20));
select * from test_python;

编写python脚本,参考如下:

代码语言:python
代码运行次数:0
复制
import cx_Oracle
userName="ygss"
password="ygss"
with cx_Oracle.connect(userName, password, "192.168.101.171/oggspdb",encoding="UTF-8") as connection:
    cursor = connection.cursor()
    cursor.execute("insert into test_python values (:1, :2)",(1,'python'))
    connection.commit()

然后执行该脚本即可

本次实验使用jupyter

这个例子是官方的

登录数据库查询:

下一篇
举报
领券