关闭

centos 6.5 64位使用python连接oracle 11g

857人阅读 评论(0) 收藏 举报
分类:
centos 6.5 64位使用python连接oracle 11g

1.安装oracle客户端
	yum install oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
	yum install oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm
	
2.配置root用户ORACLE_HOME
    export ORACLE_HOME=/usr/lib/oracle/11.2/client64/lib/
	export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME

3.安装cx_Oracle模块
    pip install cx_oracle

4.使用python连接oracle库做查询

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import cx_Oracle as db 
import os 
os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8' 

def queryOracle(sql):
    username = "dbaro"
    passwd = "xxxxxxxxxx"
    host = "192.168.2.21"
    port = "1521"
    sid = "slave"
    dsn = db.makedsn(host, port, sid)
    con = db.connect(username, passwd, dsn)
    cur = con.cursor()
    cur.execute(sql)
    result  = cur.fetchall()
    cur.close()
    con.close()
    return result


if __name__=="__main__":
    sql = "select sysdate from dual"
    result = queryOracle(sql)
    print result

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:151185次
    • 积分:3003
    • 等级:
    • 排名:第12095名
    • 原创:150篇
    • 转载:35篇
    • 译文:2篇
    • 评论:10条
    最新评论