当前位置:Gxlcms > 数据库问题 > python oracle

python oracle

时间:2021-07-01 10:21:17 帮助过:2人阅读

关于python在windows环境下链接oracle数据库的方式折腾了很久,终于搞定了,做下记录

python版本2.7

oracle链接工具版本cx_Oracle-5.1.2-11g.win32-py2.7.msi    下载链接:http://cx-oracle.sourceforge.net/

将python安装在C盘根目录

安装完成后,将oci.dll拷贝至python27目录下,将instantclient_11_2下的dll文件拷贝至C:\Python27\Lib\site-packages\目录下

配置完如上内容,就可以用python对oracle进行操作了,代码如下:

# -*- coding: utf-8 -*-

import cx_Oracle
import os

#设置中文环境,存取时避免中文乱码
os.environ[‘NLS_LANG‘] = ‘SIMPLIFIED CHINESE_CHINA.UTF8‘
#获取链接
conn = cx_Oracle.connect(‘user/password@xx.x.x.xxxx/dbname‘)
#获取游标
cursor = conn.cursor()
#执行sql
cursor.execute("select * from table_name")
#获取第一行内容
row = cursor.fetchone()
print row[0]
cursor.close ()
conn.close ()

  

 

python oracle

标签:

人气教程排行