将多个blob转换为pd

2024-09-27 02:22:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我有多个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之间


Tags: 文件代码closepdfconblobseqfile
2条回答

with open('x.pdf', mode='a') as file:

将wb+更改为a解决了问题,谢谢。你知道吗

条件type(row[0]) is cx_Oracle.BLOB总是错误的。因为cx_Oracle.BLOB是结果中出现的列类型 设置description,但类是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:

相关问题 更多 >

    热门问题