zhichaoma

安装模块

使用第三方模块 `cx_Oracle`

pip install cx_Oracle

 连接方式

import cx_Oracle as cx

#第一种
con = cx.connect(\'root\', \'root123\', \'127.0.0.1:1521/orcl\')
#第二种
con = cx.connect(\'root/root123@127.0.0.1:1521/orcl\')
#第三种
dsn = cx.makedsn(\'127.0.0.1\', \'1521\', \'orcl\')
connection = cx.connect(\'root\', \'root123\', dsn)

 简单使用

# -*- coding: utf-8 -*-
import cx_Oracle as cx		#导入模块
con = cx.connect(\'root\', \'root123\', \'127.0.0.1:1521/ORCL\')	#创建连接
cursor = con.cursor()		#创建游标
cursor.execute("select * from TDER where ID=\'28\'")	#执行sql语句
data = cursor.fetchone()		#获取一条数据
print(data)		#打印数据
cursor.close()	#关闭游标
con.close()		#关闭数据库连接

 oracle数据库的操作和mysql的pymysql操作基本相同,可以参考pymysql使用

windows下使用注意

windows下是使用需要安装`Instant Client`

1) 下载 Instant Client

地址:http://www.oracle.com/technetwork/topics/winx64soft-089540.html

 

2) 解压到一个目录,并添加到环境变量

 

其他系统下使用也需要安装这个工具,具体可以查看此文档:

  https://oracle.github.io/odpi/doc/installation.html#windows

cx_Oracle官网:https://oracle.github.io/python-cx_Oracle/

 

分类:

技术点:

相关文章:

  • 2021-08-08
  • 2021-06-19
  • 2021-07-04
猜你喜欢
  • 2022-12-23
  • 2021-12-10
  • 2021-05-14
  • 2021-10-20
  • 2021-08-25
相关资源
相似解决方案