我有多个blob块,大小都是28K字节,除了最后一个可以相同或更小。x、 pdf有94个块。代码在94个块中循环,并以无错误结束。有人用多个blob来创建一个文件。你知道吗
已经使用PL/SQL创建了275K个文件,现在被限制在4K左右,这对于UTL\u文件函数来说似乎太大了。你知道吗
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 = 0
with 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之间
将wb+更改为a解决了问题,谢谢。你知道吗
条件
type(row[0]) is cx_Oracle.BLOB
总是错误的。因为cx_Oracle.BLOB
是结果中出现的列类型 设置description,但类是cx_Oracle.LOB
,因此要检查它:文件最终为空的原因是它从未被写入。你知道吗
其余的答案都是正确的。你知道吗
为什么要用编码打开文件?它应该是不应该被转码的二进制数据。你知道吗
替换
with codecs.open('x.pdf', encoding='utf-8', mode='wb+') as file:
与
with open('x.pdf', mode='wb+') as file:
相关问题 更多 >
编程相关推荐