我有多个 blob 块,所有 28K 字节大小,除了最后一个可以相同或更少。x.pdf 有 94 个块。代码循环遍历 94 个块并无错误地结束。任何人都使用多个 blob 来创建单个文件。已经使用 PL/SQL 创建了 275K 文件,现在停留在大约 4K,这对于 UTL_FILE 函数来说似乎太大了。con = cx_Oracle.connect('sysadm/password@mydb')cur = con.cursor() sql = 'select count(*) from chunk_record where filename = :sfn'cur.execute(sql, sfn = 'x.pdf')z = cur.fetchone()[0]y = 0with codecs.open('x.pdf', encoding='utf-8', mode='wb+') as file: bcur = con.cursor() for y in range (z): print(y) bsql = 'select file_data from chunk_record where filename = :sfn and file_seq = :seq' bcur.execute(bsql, sfn = 'x.pdf', seq = y) if type(bcur.fetchone()[0]) is cx_Oracle.BLOB: file.write(bcur.fetchone()[0].read()) bcur.close()file.close()cur.close()con.close()下面的python代码正在生成大小为零的x.pdf。当我尝试以 pdf 格式打开时,它会出错。大小应该在28K*93 ~ 28K*94之间
2 回答

慕雪6442864
TA贡献1812条经验 获得超5个赞
条件type(row[0]) is cx_Oracle.BLOB始终为假。由于cx_Oracle.BLOB是列型出现在结果集中描述,但类是cx_Oracle.LOB如此以检查代替:
row = bcur.fetchone()
if isinstance(row[0], cx_Oracle.LOB):
file.write(row[0].read())
该文件最终为空的原因是它从未被写入。
其余的答案是正确的。
你为什么用编码打开文件?它应该是不应转码的二进制数据。
代替 with codecs.open('x.pdf', encoding='utf-8', mode='wb+') as file:
和 with open('x.pdf', mode='wb+') as file:
添加回答
举报
0/150
提交
取消