Answer the question
In order to leave comments, you need to log in
What is the correct way to export LOB value to JOSN using cx_Oracle?
Hello.
you need to export information from Oracle and fill it in JSON
#из наименований колонок делаю словарь
for i in range(0, len(cursor.description)):
col_names.append(cursor.description[i][0])
pp = pprint.PrettyPrinter(width=1024)
#далее разбираю курсор для JSON
for row in cursor:
count_rows+=1
row_content_json=[]
for col, val in zip(col_names, row):
result_inside[col] = val
row_content_json.append(result_inside[col])
# print (col," :: ",val)
file.write(json.dumps(row_content_json, default = myconverter))
Answer the question
In order to leave comments, you need to log in
found such a solution, a question with the conditionality of checking the presence of the read attribute
for row in cursor.fetchall():
count_rows+=1
result_inside={}
row_content=[]
for col, val in zip(col_names, row):
# проверяем наличие атрибута у объекта, если CLOB то приеняем read
if hasattr(val, 'read'):
result_inside[col] = val.read()
else:
result_inside[col] = val
row_content.append(result_inside[col])
json_file.write(json.dumps(result_inside, default = myconverter))
for row in cursor:
count_rows+=1
result_inside={}
row_content=[]
for col, val in zip(col_names, row):
# проверяем наличие атрибута у объекта, если CLOB то приеняем read
if hasattr(val, 'read'):
result_inside[col] = val.read()
else:
result_inside[col] = val
row_content.append(result_inside[col])
json_file.write(json.dumps(result_inside, default = myconverter))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question