Nov-17-2019, 02:26 PM
Hi,
I am trying to store blob data from my oracle database using python and trying to store it in a local folder in .zip format. So i have two codes now one of which is running fine but fetching only one row and storing it as .zip in a folder, but the other one in which i am trying to fetch multiple row , not working , Probably i am doing some basic mistake, but not able to figure out , so please help me . Below are the codes:-
code 1-running fine and fetching only one row and storing it as .zip in a folder:-
Thanks, Aditya
I am trying to store blob data from my oracle database using python and trying to store it in a local folder in .zip format. So i have two codes now one of which is running fine but fetching only one row and storing it as .zip in a folder, but the other one in which i am trying to fetch multiple row , not working , Probably i am doing some basic mistake, but not able to figure out , so please help me . Below are the codes:-
code 1-running fine and fetching only one row and storing it as .zip in a folder:-
import cx_Oracle import numpy as np import pandas as pd con = cx_Oracle.connect("OPTDB1", "OPTDB1", "INDLIN2112:1524/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()code 2-Throwing error and unable to fetch multiple row and storing it as .zip in a folder:-
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()Error:-
Error:blobdata= np.array(row[1].read())
AttributeError: 'str' object has no attribute 'read'
Process finished with exit code 1
Please help me out here. Thanks, Aditya