0

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.

5
  • 1
    Do you mean that you're trying to query all of the rows in a database table and save them to a file? What kind of file - CSV? There's several options in cx_oracle for fetching 1 row, multiple rows, or all the rows. You can also use a library like pandas Commented Nov 18, 2021 at 14:29
  • ... what do you mean, specifically ? You just need to write the content into a file. Commented Nov 18, 2021 at 14:31
  • there's blob files that i want to extract/download but yeah i could just open them one by one and write them in files but i don't know if it's quicker and i didn't knew cx_oracle could do it i'll look at how it works thanks Commented Nov 18, 2021 at 14:40
  • 1
    If the binary files stored as blob are text files, you can use a function to convert the blob to a clob, then download the clob as text in a normal extraction. The problem comes if the blob files are something different, like pictures or audio Commented Nov 18, 2021 at 15:43
  • 1
    Review the cx_Oracle doc cx-oracle.readthedocs.io/en/latest/user_guide/tuning.html and cx-oracle.readthedocs.io/en/latest/user_guide/lob_data.html Commented Nov 18, 2021 at 22:15

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

2 Comments

i see but when i open the file within the table F.write will go through the entire file and write it in another ?
I assume in your table you have the full file contents that what to be written in a file. So only one f.write

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.