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     
上一篇:Android上传图片到PHP服务器并且支持浏览器上传文件(word、图片、音乐等)


下一篇:php的源代码包构建一个空的php扩展。