【发布时间】:2020-03-11 12:57:32
【问题描述】:
您好,我正在尝试使用 python 从我的 oracle 数据库中存储 blob 数据,并尝试以 .zip 格式将其存储在本地文件夹中。所以我现在有两个代码,其中一个运行良好,但只获取一行并将其作为 .zip 存储在一个文件夹中,但另一个我试图获取多行,不工作,可能我正在做一些基本的错误,但无法弄清楚,所以请帮助我。以下是代码:-
代码 1-运行良好并且只获取一行并将其作为 .zip 存储在一个文件夹中:-
import cx_Oracle
import numpy as np
import pandas as pd
con = cx_Oracle.connect("OPTDB90", "OPTDB90", "INDLIN2338:1521/OPTEPC1")
cursor = con.cursor()
sql_string = """SELECT F_name, F_released_data FROM epc_project where rownum<5"""
cursor.execute(sql_string)
#Path="C:\Users\adityasi\Desktop\MY Important\QueryGeneratorPytthonFinal\Project\EPCPROJECTS"
row = cursor.fetchone()
blobdata = np.array(row[1].read())
cursor.close()
filename = str(row[0]) + ".zip"
f = open(filename, 'w+b')
binary_format = bytearray(blobdata)
f.write(binary_format)
f.close()
代码 2-引发错误,无法获取多行并将其作为 .zip 存储在文件夹中:-
import cx_Oracle
import numpy as np
import pandas as pd
con = cx_Oracle.connect("OPT", "OPT", "INDLIN2338:1521/OPT1")
cursor = con.cursor()
sql_string = """SELECT F_name, F_released_data FROM epc_project where rownum<5"""
cursor.execute(sql_string)
rows = cursor.fetchall()
for row in rows:
blobdata= np.array(row[1].read())
cursor.close()
filename =str(row[0]) + ".zip"
con.close()
f = open(filename, "wb")
binary_format = bytearray(blobdata)
f.write(binary_format)
f.close()
错误:-
blobdata= np.array(row[1].read())
AttributeError: 'str' object has no attribute 'read'
Process finished with exit code 1
请帮帮我。 谢谢, 阿迪亚
【问题讨论】:
-
在stackoverflow.com/questions/58841272/… 继续您的问题可能会更好,而且您也没有显示您的问题代码。
标签: python oracle blob cx-oracle