zoukankan      html  css  js  c++  java
  • Python使用cx_Oracle模块连接操作Oracle数据库

    1. 简单介绍

    cx_Oracle 是一个用来连接并操作 Oracle 数据库的 Python 扩展模块, 支持包含 Oracle 9.2 10.2 以及 11.1 等版本号

    2.安装

    最好是去官网http://cx-oracle.sourceforge.net/上下载安装,我自己通过pip和easy install安装都失败了,我是在win8.1的环境下安装的


    3.使用

    使用就非常easy,下面为代码演示样例

    #!/usr/bin/env python
    #-*- coding:utf-8 -*-
    
    import cx_Oracle  
    import random
    import os
    import time
    
    
    
    
    
    conn = cx_Oracle.connect('username/password@ip/SID')    
    cursor = conn.cursor ()  
    
    sql_string = "SELECT max(id) from tb_test"
    cursor.execute(sql_string)
    row = cursor.fetchone()
    v_id = int(row[0]) + 1
    print v_id
    
    
    
    current_date = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
    
    
    sql_string="INSERT INTO TB_TEST(TID,CREATE_DATE) " 
    "VALUES ("+str(v_id)+",to_date('"+str(current_date)+"','yyyy-mm-dd hh24:mi:ss'))"
    #print sql_string
    cursor.execute(sql_string)
    
    
    
    conn.commit()
    cursor.close ()  
    conn.close ()  
    
    

    
  • 相关阅读:
    npm
    React
    php区分new static 和new self
    tiny java web server
    算法可视化
    在线markdown编辑器
    JAVA
    linux find命令
    自定义windows新建菜单
    floyd算法
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/5116706.html
Copyright © 2011-2022 走看看