Home > Software engineering >  Extract files from an oracle database with Python
Extract files from an oracle database with Python

Time:11-20

i'm using cx_Oracle to access mon Oracle database i've been looking for a while a way to extract files from my database but i can't find the solution to it. And by extracting i mean download. Here's what i got so far :

from types import prepare_class
from typing import overload
import cx_Oracle

dsn_tns = cx_Oracle.makedsn('****', '****', service_name='****')
conn = cx_Oracle.connect(user=r'****', password='****', dsn=****)

c = conn.cursor()
c.execute('my request')

for row in c:
    print (row[0], '-', row[1])
conn.close()

i don't know if i need to use an external library or directly with a request.

CodePudding user response:

If you have a column with the name and one with file contents you do something like :

for fileName,fileContents in c.execute('select fileName,file contents from the_table'):
    with open(fileName, w) as f:
        F.write(fileContents)
  • Related