zoukankan      html  css  js  c++  java
  • python3利用cx_Oracle访问Oracle数据库

    1、安装Oracle客户端instantclient
    注意安装的版本,本人安装的是instantclient_11_1版本的,安装instantclient_12_2版本的时候会因系统解析不了dll报错。
    (1)下载完成后解压到一个目录下,如:E:instantclient_11_1
    (2)增加环境变量:
      TNS_ADMIN,值为E:instantclient_11_1
      NLS_LANG,值为SIMPLIFIED CHINESE_CHINA.ZHS16GBK,这是为了防止中文乱码
      创建一个监听文件tnsnames.ora到E:instantclient_11_1
    2、安装对应版本的cx_Oracle
    下载地址:https://pypi.python.org/pypi/cx_Oracle/5.2.1
    (1)这里Oracle客户端为11.1版本的,python为3.4版本,操作系统为64位,所以需要下载cx_Oracle-5.2.1-11g.win-amd64-py3.4.exe (md5)版本的cx_Oracle
    (2)下载完成后,直接双击安装
    (3)安装完成后,将客户端(即:E:instantclient_11_1目录)下的所有dll文件拷贝到python的包目录下,即C:Python34Libsite-packages文件夹下
    3、使用测试

    # --------oracle链接数据库----------------------------
    import cx_Oracle
    print(cx_Oracle.clientversion()) #打印cx_oracle版本
    student1 = {'id':1011 ,
    'name': 7,
    'age': 18}
    conn = cx_Oracle.connect('czth_sales/123456@127.0.0.1:1521/ORCL') #cx_Oracle.connect("用户名/密码@服务器地址/服务器名")
    sql = 'select * from student where id=%s' % (student1['id'])
    cur = conn.cursor()
    cur.execute(sql)
    result = cur.fetchall()
    print(result)
    conn.close() #关闭连接
  • 相关阅读:
    Poj 3713 Transferring Sylla 3-连通
    SPOJ 7758 Growing Strings AC自动机DP
    ural 1209. 1,10,100,1000.....
    ural 1197. Lonesome Knight
    ural 1149. Sinus Dances
    优先级队列
    Codeforces Round #384 (Div. 2) C. Vladik and fractions
    Codeforces Round #384 (Div. 2) B. Chloe and the sequence
    Codeforces Round #384 (Div. 2) A. Vladik and flights
    POJ 1246 Find The Multiple
  • 原文地址:https://www.cnblogs.com/wapn/p/9601910.html
Copyright © 2011-2022 走看看