python 读取数据库中的BLOB类型字段,并存储文件到本地

import os
import cx_Oracle
os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'

db_orcl = cx_Oracle.connect("用户/sid@ip/orcl")
cr_orcl = db_orcl.cursor()
cr_orcl.execute("select * from user ")
rs_user = cr_orcl.fetchall()


for user in rs_user:
    userId = user[0]
    print(userId)
    if user[1] == '':
        continue
    blob = user[1].read()
    f = open("D:\\allImages\\"+userId+".jpg", "wb")
    f.write(blob)
    f.close()

db_orcl.commit()
cr_orcl.close()

你可能感兴趣的:(python)