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

哈哈,看来我的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     

 

上一篇:微信小程序开发系列七:微信小程序的页面跳转


下一篇:Java 8 Default Methods Explained in 5 minutes