简体   繁体   English

使用 Python 从 oracle 数据库中提取文件

[英]Extract files from an oracle database with Python

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.我正在使用cx_Oracle访问 mon Oracle 数据库我一直在寻找一种从数据库中提取文件的方法,但我找不到解决方案。 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.我不知道我是否需要使用外部库或直接请求。

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM