码迷,mamicode.com
首页 > 数据库 > 详细

Python中通过cx_oracle操作ORACLE数据库的封闭函数

时间:2016-08-19 12:35:37      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:

哈哈,看来我的SQL自动化发布,马上就全面支持ORACLE,MYSQL,POSTGRESQL,MSSQL啦。。。

http://blog.csdn.net/swiftshow/article/details/7383481

def Oracle_Exec(SqlStr):
    "Execute oracle command"
    conn = cx_Oracle.connect(DB_UserName, DB_UserPwd, DB_ConnectStr)    
    cursor = conn.cursor()
    try:
        cursor.execute(SqlStr)
        conn.commit()
        return True    
    except:
        conn.rollback()
        print "Exec sql failed: %s" % SqlStr
        return False
    finally:        
        cursor.close()
        conn.close()
        
def Oracle_Query(SqlStr, debug = 0):
    "Execute oracle query, and return datalist"
    datalist = []   
    conn = cx_Oracle.connect(DB_UserName, DB_UserPwd, DB_ConnectStr)
    cursor = conn.cursor()
    try:
        cursor.execute(SqlStr)    
        while 1:     
            rs = cursor.fetchone()
            if rs == None:
                break
            datalist.append(rs)
        if debug:
            fieldnames = []
            for field in cursor.description:
                fieldnames.append(field[0])
            print fieldnames
            print datalist
            print "Query success!"            
    except:
        print "Exec sql failed: %s" % SqlStr         
    finally:        
        cursor.close()
        conn.close()
        return datalist     

 

Python中通过cx_oracle操作ORACLE数据库的封闭函数

标签:

原文地址:http://www.cnblogs.com/aguncn/p/5787005.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!